代码:
try
{
MailAddress from = new MailAddress("[email protected]");
MailAddress to = new MailAddress("[email protected]");
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the SmtpClient class.";
message.Body = @"Using this feature, you can send an e-mail message from an application very easily.";
SmtpClient client = new SmtpClient("000.000.0.000");
client.Send(message);
}
catch (Exception f)
{
throw f;
}
}
错误:
System.Net.Mail.SmtpFailedRecipientException: 邮箱不可用。 服务器响应为: 5.7.1 Unable to relay for [email protected]
我第一次用这个东西。。不知道哪里出错了。。希望知道的大哥大姐可以帮帮我。谢谢了!
try
{
MailAddress from = new MailAddress("[email protected]");
MailAddress to = new MailAddress("[email protected]");
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the SmtpClient class.";
message.Body = @"Using this feature, you can send an e-mail message from an application very easily.";
SmtpClient client = new SmtpClient("000.000.0.000");
client.Send(message);
}
catch (Exception f)
{
throw f;
}
}
错误:
System.Net.Mail.SmtpFailedRecipientException: 邮箱不可用。 服务器响应为: 5.7.1 Unable to relay for [email protected]
我第一次用这个东西。。不知道哪里出错了。。希望知道的大哥大姐可以帮帮我。谢谢了!
邮件类:
public bool SendMail(string to)
{
MailMessage sm=new MailMessage();
sm.From=ConfigurationSettings.AppSettings["mailfrom"];
sm.To=to;
sm.Subject=ConfigurationSettings.AppSettings["mailsubject"];
sm.Body=ConfigurationSettings.AppSettings["mailbody"];
sm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",
"1");
sm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",ConfigurationSettings.AppSettings["mailsendusername"]);
sm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",ConfigurationSettings.AppSettings["mailsenduserpwd"]);
SmtpMail.SmtpServer=ConfigurationSettings.AppSettings["smtpserver"];
try
{
SmtpMail.Send(sm);
return true;
}
catch
{
return false;
}
}web.config的设置: <appSettings>
<add key="mailfrom" value=""/>
<add key="mailsubject" value=""/>
<add key="mailbody" value=""/>
<add key="mailsendusername" value=""/>
<add key="mailsenduserpwd" value=""/>
<add key="smtpserver" value=""/>
</appSettings>
可以问一下这个是什么?
是读取 web.config 文件的 AppSettings 节点的 smtpserver 这个标签的数据
你要愿意的话照样可以做成 类,把 smtpserver,user,password,subject,body 等做成属性
下面我来回答这个问题吧!~
把开Internet信息服务,右击 默认smtp邮件服务器 ,访问,中断 点选 "仅以下列表除外",就ok了!~