/// <param name="smtp">发件服务器</param>
/// <param name="pwd">发件人密码</param>
/// <param name="sendMail">发件人邮箱</param>
/// <param name="recipientMail">收件人邮箱</param>
/// <param name="sendUsername">发送人姓名</param>
/// <param name="recipientUsername">收件人姓名</param>
/// <param name="Subject">邮件主题</param>
/// <param name="Body">邮件内容</param>
/// <returns>是否发送成功</returns>
public string sendMail(string smtp,string pwd,string sendMail,string recipientMail,string sendUsername,string recipientUsername,string Subject,string Body)
{
try
{
System.Net.Mail.SmtpClient client = new SmtpClient(smtp);//初始化服务器
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(sendMail, pwd);//发送人的账户,密码
client.DeliveryMethod = SmtpDeliveryMethod.Network;//指定如何处理待发邮件
MailAddress addressFrom = new MailAddress(sendMail, sendUsername); //发件人地址,姓名
MailAddress addressTo = new MailAddress(recipientMail, recipientUsername);//收件人地址,姓名
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(addressFrom, addressTo); //发信
message.Sender = new MailAddress(sendMail);
message.Subject = Subject;
message.Body = Body;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
client.Send(message);
return "true";
}
catch(Exception ex)
{
return (ex.Message);
}
}