Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
5abi0001
Creator
Creator

Send Email to Contacts

Hi Com,

i have a question! I habe a table/field where u can find some emailadresses. Now i want a Button and if i click on it, i want to send them all an email. I tought that if i create a button, select action, open url and with the conact-function and mailto, it will work, but it does not work. Can someone help me. Im new

1 Solution

Accepted Solutions
5abi0001
Creator
Creator
Author

Hi thanks, i already managed it. I used the Action open URL and use the function mailto as i wrote before. But thank u alot. 🙂

View solution in original post

2 Replies
Frank_Hartmann
Master II
Master II

1.   create a Variable, e.g.

      vEmailadresses = concat(DISTINCT(email),';')  

      (Note: email is the Field containing the adresses)

2.    add following code into mudule and adapt Infos according your environment:

Sub SendMail

Dim objEmail

set v=ActiveDocument.Variables("vEmailadresses")

getEmail = v.GetContent.String

'msgbox(getEmail)

Emailreceiverlist = getEmail

timestamp1 = Timer

Timestamp="-"&Year(Now())&"-"&Month(Now())&"-"&Day(Now())&"--"&Hour(Now())&"-"&Minute(Now())&"-"&Second(Now())

Const cdoSendUsingPort = 2 ' Send the message using SMTP

Const cdoBasicAuth = 1 ' Clear-text authentication

Const cdoTimeout = 60 ' Timeout for SMTP in seconds

mailServer = "smtp.gmail.com" 'adapt with your emailproviders smtp info

SMTPport = 465

mailusername = "YourEmail@gmail.com"     'adapt with your credentials

mailpassword = "YourPassword" 'adapt with your credentials

mailto = Emailreceiverlist

mailSubject = "Report"&Timestamp

mailBody = "Attached the current Report"

Set objEmail = CreateObject("CDO.Message")

Set objConf = objEmail.Configuration

Set objFlds = objConf.Fields

With objFlds

.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort

.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServer

.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPport

.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = cdoTimeout

.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasicAuth

.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailusername

.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailpassword

.Update

End With

objEmail.To = mailto

objEmail.From = mailusername

objEmail.Subject = mailSubject

objEmail.TextBody = mailBody

objEmail.AddAttachment "C:\Users\Admin\Desktop\Test.csv" 'If you want to add an attachment put path of file here

objEmail.Send

Set objFlds = Nothing

Set objConf = Nothing

Set objEmail = Nothing

timestamp2 =  Timer       

MsgBox("the email sent to"&" "&adressat&""&" was successfully transferred."&" "&" the sendingprocess took "&"  "&Round((timestamp2-timestamp1)/60, 2)&"  "&"min.")  

End Sub

If you are using gmail for sending the emails make sure that the following option is enabled:

Account settings

hope this helps

5abi0001
Creator
Creator
Author

Hi thanks, i already managed it. I used the Action open URL and use the function mailto as i wrote before. But thank u alot. 🙂