日期:2014-05-17 浏览次数:20887 次
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Mail;
using System.Configuration;
namespace WindowsFormsApplication1
{
public class Mail
{
public static bool Send(string to, string title, string content, bool MailServerBodyHtml)
{
try
{
System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage();
message.To = to;
message.From = "1197312019@qq.com";
message.Subject = title;
message.BodyFormat = System.Web.Mail.MailFormat.Html;
message.BodyEncoding = Encoding.UTF8;
message.Body = content;
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "********@qq.com"); //set your username here
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "*******"); //set your password here
//if (Convert.ToInt32(ConfigurationManager.AppSettings["MailServerPort"].ToString()) != 25)
//{
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);//465
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");