SMTP error while sending a message through Gmail

0 votes
asked Mar 12, 2010 by Aaron1 (160 points)
edited Apr 1, 2010

This is the error when i tried to test the following codes below:

ERROR --> Must issue a STARTTLS command first. 15sm458594bwz.12 (530).

Dim message As New MailMessage

    message.From = New MailAddressCollection("from@gmail.com")
    message.To = New MailAddressCollection("to@gmail.com")
    message.Subject = "This is a simple message"
    message.BodyText = "Hello, Joe!"
    message.BodyHtml = "Hello, <b>Joe</b>!"


Dim smtp As New Smtp

    smtp.Connect("smtp.gmail.com", 587)
    smtp.Send(message) <-- The error occurs when it reads this line of code**
    smtp.Disconnect()
    smtp.Dispose()
Applies to: Rebex Secure Mail

4 Answers

0 votes
answered Mar 12, 2010 by Aaron1 (160 points)
edited Mar 12, 2010

or how to enable SSL?

+1 vote
answered Mar 12, 2010 by Martin Vobr (12,940 points)
edited Apr 1, 2010

To enable the SMTP/SSL calling a different variant of a Connect method is needed.

smtp.Connect("smtp.gmail.com",587, Nothing, SmtpSecurity.Explicit)

Gmail also requires you to provide a valid username and password when sending email. The whole code for sending the email via smtp.gmail.com follows:

    Dim message As New MailMessage

    message.From = New MailAddressCollection("from@gmail.com")
    message.To = New MailAddressCollection("to@gmail.com")
    message.Subject = "This is a simple message"
    message.BodyText = "Hello, Joe!"
    message.BodyHtml = "Hello, <b>Joe</b>!"


    Dim smtp As New Smtp

    ''# connect using explicit SSL
    smtp.Connect("smtp.gmail.com", 587, Nothing, SmtpSecurity.Explicit)

    ''# authenticate
    smtp.Login("myaccount@googlemail.com", "mypassword")

    ''# send the message
    smtp.Send(message) 

    ''# cleanup
    smtp.Disconnect()
    smtp.Dispose()

Note that you have to reference the Rebex Secure Mail component when using the SMTP/SSL.

0 votes
answered Mar 15, 2010 by Aaron2 (140 points)
edited Mar 15, 2010

Thanks Martin!

Tried your suggestion and it works by using Rebex Secure Mail component!

Thank you very much.

commented Mar 15, 2010 by Martin Vobr (12,940 points)
Great. It's nice to know that you've got it working. If the answer works could you please mark my answers as the correct one by clicking on the check box icon left to the proposed answer? This would help future visitors find the working solution.
0 votes
answered Mar 29, 2010 by aaron (140 points)
edited Mar 29, 2010

Thanks Martin! I will try your other suggestion

...