I have a table as following information. I want to send an email in one click to all the users with a corresponding PIN code.
The user should receive the email like this:
Send to (User_Email)
body of the email :
" Hello (user_name) your pin code is (code)"
I have the email server code and it's working fine. I just need the function procedure of finding values for each user with corresponding PIN code and send it to him, then move to the next row and do the same thing until the row is empty. I want to do it in one click.
Public Function Send()
'=========== Dim variables =========
Dim str_body As String
Dim Name As Range
Dim pincode As Range
Dim user_email As Range
'=========== Dim variables =========
'==================================================================
'================< Email server >==================================
Set cdomsg = CreateObject("CDO.message")
With cdomsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = "587"
.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") = "blah blah@blah.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "blah"
.Update
End With
'==================================================================
' The procedure is to find the value in database with correspond information
'==================================================================
(( I need the procedure to call the values ))
'===================================================================
'===================================================================
With cdomsg
strBody = strBody & "<span><br/>This Email was sent from Application </span>"
strBody = strBody & "<span>Hello : " & Name & " your pin code is: " & pincode & "</span><br/>"
'====================================================================
.To = user_email
.From = "blah@gmail.com"
.Subject = "Pin code application"
.HTMLBody = strBody
.Send
MsgBox "Login details has been sent to your Email"
End With
Set cdomsg = Nothing
End Function====================================================================```