Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
devans_1
Creator
Creator

Sending an email via a macro

I am trying to create a macro to send a test email using the examples on the forum. I created

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.btinternet.com"
     Const SMTPPort = 25                  'Port number for SMTP
     Const SMTPTimeout = 60               'Timeout for SMTP in seconds

     'Sending mail

     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")= SMTPServer
       .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")= cdoBasic
       .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
       .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") ="<my account name>"
       .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="<my password>"
       .Update
     End With

     objEmail.To = "<my accountname>"
     objEmail.From = "<my accountname>"
     objEmail.Subject = "test"
     objEmail.TextBody = "test text"


     objEmail.Send                              'FAILS HERE


     Set objFlds = Nothing
     Set objConf = Nothing
     Set objEmail = Nothing
     msgbox ("Test Mail Sent")

end function

I require authentication to send this which I have put in the code. The problem is that I get an error when sending.

The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available

All the details appear correct but it does not work. Does anyone know what is wrong ? Also, in user preferences, I have set up the same email account using an AUTH LOGON authentication and this works fine. What I would really like is to be able to send an email using the details set up here rather than having to put user names and passwords in the code.

Any help is appreciated.

David

5 Replies
Not applicable

HI,

Did you manage to solve this?

/Daniel

vikasmahajan


' SMTP server details



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



.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "your smtp server no"



if len(vUser) > 0 then



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



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



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



else



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



end if



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



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



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



.Update

Dear David

Please check with SMTP server setting given below I am able to send the mails from qlikview server automatically.

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.
If you want to go quickly, go alone. If you want to go far, go together.
vikasmahajan

Const SMTPServer = "mail.btinternet.com"   here you need to put smtp server ip address.

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.
If you want to go quickly, go alone. If you want to go far, go together.
Not applicable

Hi

I found the error, I had to change the smtpauthenticatemethod to cdoAnonymous instead of cdobasic.

/Daniel

devans_1
Creator
Creator
Author

Thanks everyone for your comments but none of it works. I originally had cdoAnonymous but this fails. I am baffled.