VB.net sendmail smtp error

2.6k views Asked by At

I'm using the following code to send an email from my vb.net web application.

Public Function SendMail(ByVal strTo As String, ByVal strFrom As String, _
                            ByVal strSubject As String, ByVal strBody As String) As String
        Try

            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Credentials = New _
            Net.NetworkCredential("ns1.jasmine.arvixe.com", "<password>")
            SmtpServer.Port = 587
            SmtpServer.Host = "mail.<mydomain>.com"
            mail = New MailMessage()
            mail.From = New MailAddress(strFrom)
            mail.To.Add(strTo)
            mail.Subject = strSubject
            mail.IsBodyHtml = True
            mail.Body = strBody
            SmtpServer.Send(mail)
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

It works fine when I use my personal live.co.uk email address as the strFrom value, or even a made-up email address. But when I use a different one ([email protected]), which is perfectly valid and working, I get the following error:

"The SMTP server requires a secure connection or the client was not authenticated. The server response was: SMTP authentication is required."

Why does this happen?

1

There are 1 answers

0
rskar On BEST ANSWER

After a look at spec RFC 2554 (http://www.faqs.org/rfcs/rfc2554.html) my guess would be that the receiving/relaying server is employing some sort of authentication scheme that ensures that the email actually came from wherever strFrom indicates (a valid account on the server indicated after the @).

Item 5 of that spec, "The AUTH parameter to the MAIL FROM command" is of particular interest.

Since this "AUTH parameter to the MAIL FROM command" isn't used everywhere, it may explain why things work for some email addresses and not for others.