2 Replies Latest reply: Oct 30, 2012 1:28 AM by Kabilan Kumarasamy RSS

    How to send a mail through macro?

    Kabilan Kumarasamy

      Hi All,

       

      I want to know How to send a mail through macro?

       

      I have write the script like below , but it is not working

       

      function sendMailTest()

                Dim objEmail

       

                Const cdoSendUsingPort = 2           ' Send the message using SMTP

       

       

                Const cdoAnonymous = 0           'Do not authenticate

                Const cdoBasic = 1                     'basic (clear-text) authentication

                Const cdoNTLM = 2                     'NTLM

       

       

       

                Const SMTPServer = "mail.myserver.net"

                Const SMTPPort = 25                             ' Port number for SMTP

                Const SMTPTimeout = 60                          ' Timeout for SMTP in seconds

       

      // Till here Script is working

       

      // From here the script is not working

       

                'Sending mail

                Set objEmail = CreateObject("CDO.Message")

       

       

                Set objConf = objEmail.Configuration

                Set objFlds = objConf.Fields

                With objFlds

                          '---------------------------------------------------------------------

                             ' SMTP server details

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

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

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

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

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

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

                             .Update

                          '---------------------------------------------------------------------

                End With

       

       

                objEmail.To = "maneeswaran.kannan@Myserver.com"

                objEmail.From = "kabilan.kumarasamy@Myserver.com"

                objEmail.Subject = "test"

                objEmail.TextBody = "message de test"

       

       

                objEmail.Send

       

                Set objFlds = Nothing

                Set objConf = Nothing

                Set objEmail = Nothing

       

       

                msgbox ("Test Mail Sent")

       

      end function

       

       

       

      Please help me on this issue..

       

      Thanks In advance...

       

      Regards,

      Kabilan K