Avatar of Wayne Barron
Wayne Barron
Flag for United States of America asked on

asp.net (VB) This mail server requires authentication when attempting to send to a non-local e-mail address

Hello, All.
I am trying to get a contact email script to work.
It works when I send it to a local user on the same domain.
However, I get this when I try sending it to a user on another domain.



System.Net.Mail.SmtpException: 'Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.'


This is my code.

Front end

    <form id="form1" runat="server">
    <table border="0" cellpadding="0" cellspacing="0">
        <tr>             <td>From:</td>             <td><asp:TextBox ID="txtTo" runat="server" /></td>         </tr>         <tr>             <td>Subject:</td>             <td><asp:TextBox ID="txtSubject" runat="server" /></td>         </tr>         <tr>             <td valign = "top">Body:</td>             <td><asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" Height="150" Width="200" /></td>         </tr>         <tr>             <td></td>             <td><asp:Button ID="btnSend" Text="Send" runat="server" OnClick = "SendEmail" /></td>         </tr>     </table>     </form>

Open in new window

Back-end

Imports System.Net.Mail
Partial Class VB
    Inherits Page

    Protected Sub SendEmail(sender As Object, e As EventArgs) Handles btnSend.Click
        Try
        Dim mail As New MailMessage
        Dim smtpServer As New SmtpClient("mail.yourdomain.com")
        Dim strSender As String = "info@yourdomain.com"
        Dim txtPass As String = "password"

        mail.From = New MailAddress(strSender)
        mail.To.Add(txtTo.Text)
        mail.Bcc.Add(strSender)
        mail.Subject = txtSubject.Text
        mail.Body = txtMessage.Text

        smtpServer.Port = 25
        Dim credential As Net.NetworkCredential = New Net.NetworkCredential(strSender, txtPass)
        smtpServer.Credentials = credential
        smtpServer.EnableSsl = False
        smtpServer.Send(mail)

        Response.Write("Your email has been sent, maybe?")
        smtpServer.Dispose()
        Catch ex As Exception
        MsgBox(ex.Message, vbCritical)
        End Try
    End Sub
End Class

Open in new window

I've been working with cdosys for well over a decade now with classic asp, so I am in uncharted territory with this one.

Any help on this would be great.
Wayne

ASP.NETVB Script

Avatar of undefined
Last Comment
Wayne Barron

8/22/2022 - Mon
Kimputer

Use a free mail client (or Outlook) and use the same SMTP settings (port 25, authentication as you described, email and password). If the mail client has the same problem, try to fix that first (use port 465/587 with SSL or STARTTLS). If you fixed it, use those settings in your mail code.
There might be a few caveats though, CDO is quite old and might not support the settings you discovered to use with your mail client.
ASKER CERTIFIED SOLUTION
Wayne Barron

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23