public bool SendEmail(string to, string fromtemp,string mestitle,string mescontent)
{
if (to != "" && fromtemp != "")
{
//从web.config读取定义发送邮件的client
string str = System.Configuration.ConfigurationSettings.AppSettings["client"];
SmtpClient client = new SmtpClient(str);
client.UseDefaultCredentials = false;
string from = System.Configuration.ConfigurationSettings.AppSettings["from"];//实际发件人
string frompwd = System.Configuration.ConfigurationSettings.AppSettings["frompwd"];//发送人邮箱密码
client.Credentials = new System.Net.NetworkCredential(from, frompwd);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
MailAddress addressFrom = new MailAddress(fromtemp);//显示发件人
MailAddress addressTo = new MailAddress(to);//收件人
MailMessage message = new MailMessage(addressFrom, addressTo);
message.Sender = new MailAddress(fromtemp);
message.Subject = mestitle;//标题
message.Body = mescontent;//内容
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
try
{
client.Send(message);
return true;
}
catch
{
return false;
}
}
else
{
return false;
}
}