protected void SendEmail(string strFrom, string strTo, string strCc, string strSubject, string strMessage, string lang)
{
try
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); //string sender = (string)Session["sSignInEmail"];
//string sender = "[email protected]"; strFrom = strFrom.Trim();
strTo = strTo.Trim();
strCc = strCc.Trim(); if (lang == "Japanese")
{
//msg.BodyEncoding = System.Text.Encoding.GetEncoding("Shift-JIS");
//msg.BodyEncoding = System.Text.Encoding.GetEncoding("iso-2022-jp");
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
} else
{
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
} msg.From = new System.Net.Mail.MailAddress(strFrom); //string[] toS = strTo.Split('^');
//for (int i = 0; i < toS.Length; i++)
//{
// msg.To.Add(toS[i]);
//}
msg.To.Add(strTo);
if (strCc != "")
{
string[] cctoS = strCc.Split('^');
for (int i = 0; i < cctoS.Length; i++)
{
msg.CC.Add(cctoS[i]);
}
} msg.Subject = strSubject; //from argument
//msg.Subject = Label10.Text.Trim();
msg.IsBodyHtml = true;
msg.Body = strMessage; msg.Headers.Add("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869");
msg.Headers.Add("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2869");
//msg.Headers.Add("ReturnReceipt", "1");
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(); //For get message,if send email fail.
msg.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.OnFailure;
//如果发送Email失败,回信到指定的Email Address,现在只能回到发信人(即strFrom )
msg.ReplyTo = new System.Net.Mail.MailAddress("[email protected]"); smtp.Host = "smtp-au.server-mail.com";
// smtp.Credentials = new System.Net.NetworkCredential("mb20085s", "nwc271099");
//SmtpMail.SmtpServer = "smtp-au.server-mail.com";
smtp.Send(msg); //send email out //lblArea.Text = "out";
} catch (Exception err)
{
//lblArea.Text = err.Message;
// lbl_Thanks.Text = err.Message;
}
}
{
try
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); //string sender = (string)Session["sSignInEmail"];
//string sender = "[email protected]"; strFrom = strFrom.Trim();
strTo = strTo.Trim();
strCc = strCc.Trim(); if (lang == "Japanese")
{
//msg.BodyEncoding = System.Text.Encoding.GetEncoding("Shift-JIS");
//msg.BodyEncoding = System.Text.Encoding.GetEncoding("iso-2022-jp");
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
} else
{
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
} msg.From = new System.Net.Mail.MailAddress(strFrom); //string[] toS = strTo.Split('^');
//for (int i = 0; i < toS.Length; i++)
//{
// msg.To.Add(toS[i]);
//}
msg.To.Add(strTo);
if (strCc != "")
{
string[] cctoS = strCc.Split('^');
for (int i = 0; i < cctoS.Length; i++)
{
msg.CC.Add(cctoS[i]);
}
} msg.Subject = strSubject; //from argument
//msg.Subject = Label10.Text.Trim();
msg.IsBodyHtml = true;
msg.Body = strMessage; msg.Headers.Add("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869");
msg.Headers.Add("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2869");
//msg.Headers.Add("ReturnReceipt", "1");
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(); //For get message,if send email fail.
msg.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.OnFailure;
//如果发送Email失败,回信到指定的Email Address,现在只能回到发信人(即strFrom )
msg.ReplyTo = new System.Net.Mail.MailAddress("[email protected]"); smtp.Host = "smtp-au.server-mail.com";
// smtp.Credentials = new System.Net.NetworkCredential("mb20085s", "nwc271099");
//SmtpMail.SmtpServer = "smtp-au.server-mail.com";
smtp.Send(msg); //send email out //lblArea.Text = "out";
} catch (Exception err)
{
//lblArea.Text = err.Message;
// lbl_Thanks.Text = err.Message;
}
}
说的what?。那么应该有个发送失败的回信,现现在只能是发送人收到,我希望回信到我的Email address.你现在不是发送人吗?能表达清楚点吗?
如果发送不成功不知道能不能catch的到,本人怀疑回信是server完成的
经过调试发送失败catch不到,怎么判断发送是否成功?
try
{
//发送
}
catch
{
//发送没成功
}
发送成功也可能被过滤
请问有什么方法判断发送失败,
我是想通过判断发送失败后,在发邮件给某人
就是这点代码:
msg.DeliveryNotificationOptions = System.Net.Mail.DeliveryNotificationOptions.OnFailure;
例如Try..Catch的异常。这样在catch里面写发送邮件给发信人。2.收件人的邮箱不存在,Catch没有异常。这个是没有办法通知发信人的。你要确定你到底是哪种情况发送邮件失败。按照我理解2是没有办法的。1的错误一般是你邮件服务器错,或者对方服务器拒收,邮件格式错误,这个倒是有异常。
有时候发送不成功第二天才有回信,但有时又很快。
那么完全可以自己开发一套邮件系统,
不用操作系统提供的邮件系统。
这样的话,什么你都可以掌握!我上半年做的一个工程里面,
就是这么干的。
根本就不用什么STMP协议,
就用WEB传输邮件!