Hi Imar hope you are well. I am having a problem sending email through the Email demo form. I have played about with it using many different settings â too many to mention. My code is as below and I have checked and got the smtp address of my mail server (as an IP address), a port number plus I was told that I will not need to pass in a login or password (even though I have tried it anyway).
The error I am getting is
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.
My Code behind file.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
publicpartialclassDemos_Email : BasePage
{
protectedvoid Page_Load(object sender, EventArgs e)
{
MailMessage myMessage = newMailMessage();
myMessage.Subject = "Text Message";
myMessage.Body = "Hello World, from Planet Wrox";
myMessage.From = newMailAddress("******@.net", "MarkH");
myMessage.To.Add(newMailAddress("******@.net", "This should be the receivers name"));
SmtpClient mySmtpClient = newSmtpClient();
mySmtpClient.Send(myMessage);
}
}
My web.config
Code:
<?xmlversion="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<pagestheme="Monochrome">
<!--removed styleSheetTheme="Monochrome" it messed up DarkGrey.Css-->
<controls>
<addtagPrefix="Wrox"tagName="Banner"src="~/Controls/Banner.ascx" />
</controls>
</pages>
<compilationdebug="true"targetFramework="4.0"/>
</system.web>
<!--my code for email-->
<system.net>
<mailSettings>
<smtpdeliveryMethod="Network"from = "MarkH <******@.net>">
<networkhost= "**.*.**.***"port="25"/>
</smtp>
</mailSettings>
</system.net>
<!--my code for email-->
</configuration>
Many Thanks
Mark