MailAddress fromAddress = new MailAddress("[email protected]");
MailAddress toAddress = new MailAddress("[email protected]"); //定义邮件消息
MailMessage msg = new MailMessage(fromAddress, toAddress);//邮件标题
msg.Subject = "test_title";
//邮件正文
msg.Body = "test_body";msg.IsBodyHtml = false;
使用简单邮件传输协议来传送邮件
SmtpClient sendMail = new SmtpClient();//发送邮件的服务器名或地址
sendMail.Host = ""//本機IP(與SMTP服務器上設置的一致);
//设置邮箱端口
sendMail.Port = 25;//验证发件人的身份
//sendMail.Credentials = new NetworkCredential(m_UserName, m_Password);??要與不要都有問題??//处理待发送邮件的方法
sendMail.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;//发送邮件
sendMail.Send(msg);發送郵件的代碼如上!!使用try,catch捕獲異常沒有錯誤,可是sohu收不到郵件,這是怎麼回事????
也已在smtp服務器上設置好sohu.com 網域!!麻煩幫我看看問題出在哪裡???
另公司是採用的代理上網,屏蔽了一些網站,但是sohu.com 還是可以打開的.........................
MailAddress toAddress = new MailAddress("[email protected]"); //定义邮件消息
MailMessage msg = new MailMessage(fromAddress, toAddress);//邮件标题
msg.Subject = "test_title";
//邮件正文
msg.Body = "test_body";msg.IsBodyHtml = false;
使用简单邮件传输协议来传送邮件
SmtpClient sendMail = new SmtpClient();//发送邮件的服务器名或地址
sendMail.Host = ""//本機IP(與SMTP服務器上設置的一致);
//设置邮箱端口
sendMail.Port = 25;//验证发件人的身份
//sendMail.Credentials = new NetworkCredential(m_UserName, m_Password);??要與不要都有問題??//处理待发送邮件的方法
sendMail.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;//发送邮件
sendMail.Send(msg);發送郵件的代碼如上!!使用try,catch捕獲異常沒有錯誤,可是sohu收不到郵件,這是怎麼回事????
也已在smtp服務器上設置好sohu.com 網域!!麻煩幫我看看問題出在哪裡???
另公司是採用的代理上網,屏蔽了一些網站,但是sohu.com 還是可以打開的.........................
SMTP Virtual Server是么?还是只是配置打开了IIS里面的SMTP?如果不适用第三方的smtp服务的话,只能在本机安装SMTP Server才行,单单打开IIS的SMTP是不能行的。另外,很多第三方邮箱都屏蔽了匿名SMTP服务器。
已打開并配置好SMTP Virtual Server
已打開并配置好SMTP Virtual Server
public class EmailHelper
{
public static void SendEmail(string to,string title,string content)
{
string smtpServer = ConfigHelper.Configuration.Configs["SmtpServer"];
int port;
int.TryParse(ConfigHelper.Configuration.Configs["SmtpPort"], out port);
SmtpClient client = new SmtpClient(smtpServer,port);
client.Send(ConfigHelper.Configuration.Configs["NotificationSender"], to, title, content);
}
}EmailHelper.SendEmail("[email protected]", "Server is up.", "Success.");//mydomain是我自己的
[code=ini]
$SmtpServer = localhost
$SmtpPort = 25
[/code]我曾经写过一个,是这样的。
跟你写的意思是一样的,使用的也是本机的SMTP Virtual Server,但是使用的是个人网域,也就是本机。如果不知道结果怎么样,试试SendAsync这种异步的发送,并且看看SendCompleted事件的返回消息是什么。