程序实现发邮件功能函数:
调用函数方法:
1
static public void SendEmail(string strTo, string strFrom, string strSubject, string strContent)
2
{
3
MailAddress tempToAddress = new MailAddress(strTo);
4
MailAddress tempFromAddress = new MailAddress(strFrom);
5
MailMessage tempMessage = new MailMessage(tempFromAddress, tempToAddress);
6
tempMessage.Body = strContent;
7
tempMessage.BodyEncoding = System.Text.Encoding.Default;
8
tempMessage.IsBodyHtml = true; //html格式
9
tempMessage.Priority = MailPriority.High;
10
tempMessage.Subject = strSubject;
11
tempMessage.SubjectEncoding = System.Text.Encoding.Default;
12
System.Net.NetworkCredential tempCredential = new System.Net.NetworkCredential();
13
//tempCredential.Domain = "";
14
tempCredential.UserName = "hemeng"; //用户名
15
tempCredential.Password = "aaaaaa"; //密码
16
SmtpClient tempClient = new SmtpClient();
17
tempClient.Host = "202.108.5.141"; //邮件服务器ip地址
18
tempClient.UseDefaultCredentials = true;
19
tempClient.Credentials = tempCredential;
20
tempClient.Send(tempMessage);
21
22
}
23
static public void SendEmail(string strTo, string strFrom, string strSubject, string strContent)2
{3
MailAddress tempToAddress = new MailAddress(strTo);4
MailAddress tempFromAddress = new MailAddress(strFrom);5
MailMessage tempMessage = new MailMessage(tempFromAddress, tempToAddress);6
tempMessage.Body = strContent;7
tempMessage.BodyEncoding = System.Text.Encoding.Default;8
tempMessage.IsBodyHtml = true; //html格式9
tempMessage.Priority = MailPriority.High;10
tempMessage.Subject = strSubject;11
tempMessage.SubjectEncoding = System.Text.Encoding.Default;12
System.Net.NetworkCredential tempCredential = new System.Net.NetworkCredential();13
//tempCredential.Domain = "";14
tempCredential.UserName = "hemeng"; //用户名15
tempCredential.Password = "aaaaaa"; //密码16
SmtpClient tempClient = new SmtpClient();17
tempClient.Host = "202.108.5.141"; //邮件服务器ip地址18
tempClient.UseDefaultCredentials = true;19
tempClient.Credentials = tempCredential;20
tempClient.Send(tempMessage);21

22
}23

调用函数方法:
1
SendEmail("hemeng80@gmail.com", "hemeng2008@126.com", "邮件内容:系统测试", "发送成功!!");
2
SendEmail("zrl_happy@126.com", "hemeng2008@126.com", "邮件内容:系统测试", "发送成功!!");
SendEmail("hemeng80@gmail.com", "hemeng2008@126.com", "邮件内容:系统测试", "发送成功!!");2
SendEmail("zrl_happy@126.com", "hemeng2008@126.com", "邮件内容:系统测试", "发送成功!!");

浙公网安备 33010602011771号