0 votes
by (160 points)
edited

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
by (160 points)
edited

or how to enable SSL?

+1 vote
by (13.0k points)
edited

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
by (140 points)
edited

Thanks Martin!

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

Thank you very much.

by (13.0k 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
by (140 points)
edited

Thanks Martin! I will try your other suggestion

...