Send email with System.Web.Mail
asp.net
Solution
I use This code .
MailMessage msg = new MailMessage();
msg.Body = "Body";
string smtpServer = "mail.DomainName";
string userName = "info@mysite.com";
string password = "MyPassword";
int cdoBasic = 1;
int cdoSendUsingPort = 2;
if (userName.Length > 0)
{
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", smtpServer);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", cdoSendUsingPort);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", cdoBasic);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
}
msg.To = user.Email;
msg.From = "info@Mysite.com";
msg.Subject = "Subject";
msg.BodyEncoding = System.Text.Encoding.UTF8;
SmtpMail.SmtpServer = smtpServer;
SmtpMail.Send(msg);
Problem
I want send email in asp. I use this code ``` using System.Web.Mail; MailMessage msg = new MailMessage(); msg.To = "aspnet@yahoo.com"; msg.From = "info@mysite.com"; msg.Subject = "Send mail sample"; msg.BodyFormat = MailFormat.Html; string msgBody="Hello My Friend. This is a test."; msg.Body = msgBody ; SmtpMail.SmtpServer = "localhost"; SmtpMail.Send(msg); ``` But i get error : 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. How to send email with asp?