29

I am trying to send Email

But I am getting this Error.

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

any one having any idea about it please Help me

Smily
  • 2,646
  • 4
  • 23
  • 31
  • Did you check this? http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/2bdde9e6-b57a-4b12-b476-7bcf1f8f66d5/ – Shoban Feb 06 '12 at 08:01
  • yes I had already Check all the things. All things are all right.. – Smily Feb 06 '12 at 11:50
  • Are you sure its something to do with your code and not with the server. May be try with a diff language/win forms etc? – Shoban Feb 06 '12 at 12:24

4 Answers4

19

Discovered that you can also get this error when Gmail's security settings don't allow messages to be sent from the address you intend to use. I had to enable access for less secure apps for my account in question by:

  1. Logging into the address you want to use for sending email from Excel.
  2. Visit the page https://www.google.com/settings/security/lesssecureapps
  3. Click Enable Less Secure Apps.
  4. Click Done.
Jacob Fink
  • 191
  • 1
  • 2
  • Both answers are correct and help to solve the problem. If you have locked (by default gmail is locked) you need to enable less security. So if you send much mails like spam your account can be disabled. The third possibility must be user/password incorrect, or port incorrect, etc. – Mastercafe Feb 01 '15 at 21:28
11

It's caused by a wrong username or password for the SMTP server and usually means that the server has disabled your account for spamming i you've sent 1500 mails

  • 1
    You saved my life! I confirm that this error is caused by a wrong username or password! – Evilripper Mar 06 '15 at 11:48
  • YES, I HAD THE same problem, then if figur out that my app password has been suddenly deleted. I just created a new one and it works fine – sami Jun 13 '20 at 22:58
6

Thanks for your replies, it worked! it was because I didn't have this option enabled: https://www.google.com/settings/security/lesssecureapps In case somebody needs it, this is the VBScript code I'm using in Qlikview:

SUB SendMail
    Dim objEmail

    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"
     SMTPport = 465     '25 'SMTPport = 465
     mailusername = "marcos.esgu**@gmail.com"
     mailpassword = "Ki***"

     mailto = "marcos.esgu**@*****" 
     mailSubject = "my test-deleteme" 
     mailBody = "This is the email body" 

    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:\report.pdf"
    objEmail.Send

    Set objFlds = Nothing
    Set objConf = Nothing
    Set objEmail = Nothing
END SUB
Markus Pscheidt
  • 6,853
  • 5
  • 55
  • 76
Marcos
  • 69
  • 1
  • 1
  • I think this should have been an edit to your question, or a comment. What you have written is not actually an answer. But it's good that you follow up and say thank you, never the less. – Alastair Brown Jun 02 '16 at 02:50
  • I allow in my gmail account less secure apps, but it still gives the same error. – Ezra Apr 13 '20 at 18:13
1

Had the same problem using BizTalk, where adapter default handler specified to use NTLM authentication (by default). Even though I specified to override handler on send port properties, BizTalk did not allow me to override adapter default handler. I needed to change adapter default handler in order to get it to work.

Now it works!

JERKER
  • 907
  • 8
  • 17