El *_* Ma 0 asp.net email dns smtpclient
我使用此代码在asp.net中发送电子邮件:
使用System.Net.Mail
public string SendEmail()
{
SmtpClient obj = new SmtpClient();
MailMessage Mailmsg = new MailMessage();
Mailmsg.To.Clear();
Recievers = new MailAddressCollection();
Recievers.Add(txtToAddress.Text);
SenderName = "Info";
SenderEmail = txtFromAddress.Text;
Subject = "subj";
Body = "body";
UseBcc = false;
if (UseBcc)
{
foreach (MailAddress RecieverItem in Recievers)
{
Mailmsg.Bcc.Add(RecieverItem);
}
}
else
{
foreach (MailAddress RecieverItem in Recievers)
{
Mailmsg.To.Add(RecieverItem);
}
}
Mailmsg.From = new MailAddress(SenderEmail, SenderName, System.Text.Encoding.UTF8);
Mailmsg.Subject = Subject;
Mailmsg.SubjectEncoding = Encoding.UTF8;
Mailmsg.BodyEncoding = System.Text.Encoding.UTF8;
Mailmsg.IsBodyHtml = false;
obj.Host = mail.domain.com;
System.Net.NetworkCredential BasicAuthenticationInfo = new System.Net.NetworkCredential("info@domain.com", "password");
obj.UseDefaultCredentials = false;
obj.Credentials = BasicAuthenticationInfo;
Mailmsg.Body = Body;
Mailmsg.IsBodyHtml = true;
try
{
obj.Send(Mailmsg);
return "sent";
}
catch (Exception ex)
{
return ex.ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
它正确地向我的域中定义的收件人发送电子邮件(如mail@domain.com),但我无法向其他邮件服务器发送电子邮件(如mail@yahoo.com).
我的代码有什么问题?
(愿它涉及到SmtpClient属性呢?我已经smtpclient.host设置为mail.mydomain.com ,并使用它们在我的域中定义我的邮件帐户之一的用户名和密码)
谢谢
它必须是与您的Exchange服务器相关的东西.交换规则决定了你如何与外界沟通.
在向外部网络发送电子邮件时,您必须获得一些例外
System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.1.1 User unknown
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
Run Code Online (Sandbox Code Playgroud)
如果这是错误,则表明您的交换不支持直接向外部网络发送电子邮件.因为我不是MS交换专家,但我一直在使用在我的网络中配置的交换服务器,它无法向外部网络发送电子邮件,但我们启用了电子邮件转发给联系人.
可能这可以帮到你.http://www.petri.co.il/configuring-exchange-2007-send-connectors.htm
我也建议你在https://serverfault.com/上分享这个问题
归档时间: |
|
查看次数: |
6305 次 |
最近记录: |