2 Replies Latest reply: Sep 26, 2017 3:29 AM by Prince Sabi RSS

    Send Email to Contacts

    Prince Sabi

      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

        • Re: Send Email to Contacts
          Frank Hartmann

          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
          Emailreceiverlist = getEmail
          timestamp1 = Timer 
          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
          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
          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