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>
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
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
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.