C# System.Web.Mail.MailMessage 发邮件

C# System.Web.Mail.MailMessage 发邮件

新建控制台Console项目,然后添加 System.Web引用

代码如下:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
//using System.IO.Pipes;
using System.Net;
using System.Net.Mail;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;

namespace LongtengSupremeConsole
{
    class Program
    {        
        static void Main(string[] args)
        {
            System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
            mail.To = "[email protected]";
            mail.From = "[email protected]";
            mail.Subject = "测试邮箱";
            mail.BodyFormat = System.Web.Mail.MailFormat.Html;
            mail.Body = "这是一个是测试的内容!";


            mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //身份验证  
            mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", mail.From); //邮箱登录账号  
            mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "*****"); //登录密码  
            mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);//端口  
            //mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");//SSL加密  
            System.Web.Mail.SmtpMail.SmtpServer = "smtp.aliyun.com";    //企业账号用smtp.exmail.qq.com  
            System.Web.Mail.SmtpMail.Send(mail);
            Console.WriteLine("邮件发送完成!!");
            Console.ReadKey();
        }
}
}

 

你可能感兴趣的:(C# System.Web.Mail.MailMessage 发邮件)