c# 代码
- try
- {
- MailAddress to = new MailAddress("x@x.com");//接收者邮箱;
- MailAddress from = new MailAddress("x@x.com");//发送者邮箱
- System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(from, to);
- mail.To.Add("xx@xx.com");//添加接收者
- mail.Subject = "test!! "+System.DateTime.Now;
- mail.Body = "a new mail use dotnet2.0!";
- SmtpClient client = new SmtpClient();
- client.Host = "smtpserver";//设置发送者邮箱对应的smtpserver
- client.UseDefaultCredentials = false;
- client.Credentials = new NetworkCredential("username", "password");//设置发送者邮箱对应的username和password
- client.DeliveryMethod = SmtpDeliveryMethod.Network;
- client.Send(mail);
- }
- catch (Exception e)
- {
- throw e;
- }
- finally
- {
- }