发送邮件的类

public class Mail
{
public bool ServiceSendMail(string strTo, string strSubject, string strBody, string strEncoding)
{
return common(strTo, "", strSubject, strBody, strEncoding);
}

/// <summary>
/// 邮件发送(Service邮箱),默认编码为GB2312
/// </summary>
/// <param name="strTo"></param>
/// <param name="strCc"></param>
/// <param name="strSubject"></param>
/// <param name="strBody"></param>
/// <param name="strEncoding">编码,如果为空,默认为GB2312</param>
/// <returns></returns>
public bool ServiceSendMail(string strTo, string strCc, string strSubject, string strBody, string strEncoding)
{
return common(strTo, strCc, strSubject, strBody, strEncoding);
}

/// <summary>
/// 邮件发送默认编码为GB2312
/// </summary>
/// <param name="strTo"></param>
/// <param name="strSubject"></param>
/// <param name="strBody"></param>
/// <returns></returns>
public bool ServiceSendMail(string strTo, string strSubject, string strBody)
{
return common(strTo, "", strSubject, strBody, "");
}

private static bool common(string strTo, string strCc, string strSubject, string strBody, string strEncoding)
{
bool bState = false;

try
{
//编码暂硬性规定为GB2312
Encoding encoding = Encoding.GetEncoding(936);

MailMessage Message = new MailMessage(
new MailAddress("hanjunhui127@sina.com", "hanjunhui127", encoding),
new MailAddress(strTo));

Message.SubjectEncoding = encoding;
Message.Subject = strSubject;
Message.BodyEncoding = encoding;
Message.Body = strBody;
if (strCc != "")
{
Message.CC.Add(new MailAddress(strCc));
}
SmtpClient smtpClient = new SmtpClient("smtp.sina.com");
smtpClient.Credentials = new NetworkCredential("hanjunhui127","1984127");
smtpClient.Timeout = 999999;
smtpClient.Send(Message);

bState = true;


}
catch (Exception ex)
{
throw new Exception(ex.Message);
}

return bState;
}

 


}  

阅读更多
想对作者说点什么? 我来说一句

phpmailer.zip发送邮件

2018年04月09日 23KB 下载

php使用smtp封装类发送邮件

navioo navioo

2016-06-28 13:59:12

阅读数:4779

发送邮件

2016年06月03日 20KB 下载

sendmailsample

2017年12月29日 1KB 下载

email邮件发送类

2011年02月18日 8KB 下载

没有更多推荐了,返回首页

不良信息举报

发送邮件的类

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭