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 = "test@qq.com";
            mail.From = "test@aliyun.com";
            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();
        }
}
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM