Cool.
Ill keep that in mind for future things.
I figured out how to do it in the way i first posted... so since it works just fine (so far)
ill keep it
Code:
Public Sub SendEmail()
Dim cdomsg As Object
Dim receiver As String
Dim pw As String
Dim answer As Integer
Set cdomsg = CreateObject("CDO.message")
With cdomsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "okuus83@gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "senapochtomtar12"
.Update
End With
If IsNull(Form_Login_Form.txtUsername) = True Then
MsgBox "Du måste välja ett namn i listan. Väjler du någon annans namn får de sitt lösenord skickat till sig. Så var noga med att välja ditt namn för att få ett lösenord!"
Else
answer = MsgBox("Är du " & DLookup("[Username]", "Access_Table", "[User_ID] =" & Forms![Login_Form]!txtUsername) & " med mail: " & DLookup("[Mail]", "Access_Table", "[User_ID] =" & Forms![Login_Form]!txtUsername), vbYesNo + vbQuestion, "Är du")
If answer = vbYes Then
receiver = DLookup("[Mail]", "Access_Table", "[User_ID] =" & Forms![Login_Form]!txtUsername)
pw = DLookup("[Password]", "Access_Table", "[User_ID] =" & Forms![Login_Form]!txtUsername)
' build email parts
With cdomsg
.To = receiver
.From = "okuus83@gmail.com"
.Subject = "Ditt lösenord är"
.TextBody = "Ditt lösenord är: " & pw
.Send
End With
Set cdomsg = Nothing
Else
End If
End If
End Sub
added a few messages aswell when performing the tasks.