|
想把很多函数封装成C#的dll搭建QTP框架,但是有一个函数好几天了一直没有写成功,不报任何错,也不抛exception,但是就是收不到邮件
恳请路过的大侠出手相助,晚辈谢过了
using System.Net.Mail;
using System.Net;
using System.IO;
public string SendEmail(string toAddr, string title, string content)
{
MailMessage msg = new MailMessage();
msg.To.Add(toAddr);
msg.To.Add("quicktest@yahoo.cn");
msg.CC.Add("wally.yu@mercer.com");
msg.From = new MailAddress("MercerAutomation@gmail.com", "Automation Mercer", System.Text.Encoding.UTF8);
msg.Subject = title;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = content;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = false;
msg.Priority = MailPriority.Normal;
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("MercerAutomation@gmail.com", "EssMercer");
client.Port = 587; //587, 465, 995
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
object userState = msg;
try
{
client.SendAsync(msg, userState);
return "sucess";
}
catch (SmtpException ex)
{
return ex.Message + "SendEmail error";
}
} |
|