还有这里用的发送邮件类是 System.Net.Mail.MailMessage,而不是System.Web.Mail .MailMessage类,因为前面的类是新版本的类,我也鼓励大家用新类。
代码如下:
/// <summary>
/// 发送邮件给供应商
/// </summary>
/// <param name="form"></param>
/// <param name="to"></param>
/// <param name="subject"></param>
/// <param name="body"></param>
/// <returns></returns>
public void SendEmailToSupplier(string from, string to, string subject, string body)
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new System.Net.Mail.MailAddress(from ,"新邮件");
msg.To.Add(to);
msg.Subject = subject;
msg.Body = body;
msg.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
msg.Priority = System.Net.Mail.MailPriority.High;
System.Net.Mail.SmtpClient cliect = new System.Net.Mail.SmtpClient("邮件服务器的IP");
cliect.Credentials = new System.Net.NetworkCredential("mail_box", "123456");
cliect.Send(msg);
}
/// 发送邮件给供应商
/// </summary>
/// <param name="form"></param>
/// <param name="to"></param>
/// <param name="subject"></param>
/// <param name="body"></param>
/// <returns></returns>
public void SendEmailToSupplier(string from, string to, string subject, string body)
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new System.Net.Mail.MailAddress(from ,"新邮件");
msg.To.Add(to);
msg.Subject = subject;
msg.Body = body;
msg.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
msg.Priority = System.Net.Mail.MailPriority.High;
System.Net.Mail.SmtpClient cliect = new System.Net.Mail.SmtpClient("邮件服务器的IP");
cliect.Credentials = new System.Net.NetworkCredential("mail_box", "123456");
cliect.Send(msg);
}