我要用asp发送电子邮件。
我使用这个代码
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);但我错了:
糟糕的命令序列。服务器响应是:当试图发送到非本地电子邮件地址时,此邮件服务器需要身份验证。请检查您的邮件客户端设置或与管理员联系,以验证此服务器的域或地址是否已定义。
如何用asp发送电子邮件?
发布于 2013-02-05 10:05:59
我用这个密码。
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);发布于 2013-02-02 13:53:29
您可能需要提供凭据。
示例:
smtpMail.Credentials = new NetworkCredential("username", "password")https://stackoverflow.com/questions/14662472
复制相似问题