C#代碼發郵件(以163郵箱爲例)

一、設置163郵箱的授權碼

二、發送郵件的相關代碼

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using ZSZ.Service;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            using (MailMessage mailMessage = new MailMessage())
            using (SmtpClient smtpClient = new SmtpClient("smtp.163.com"))//SMTP服務器
            {
                mailMessage.To.Add("[email protected]"); //接收郵箱
                mailMessage.Body = "這裏寫郵件正文";//郵件正文
                mailMessage.From = new MailAddress("[email protected]");//發送郵箱
                mailMessage.Subject = "這裏寫郵件標題";//郵件標題
                smtpClient.Credentials = new System.Net.NetworkCredential("****@163.com","****");//參數填smtp用戶名、授權碼
                smtpClient.Send(mailMessage);
            }
            Console.ReadKey();
        }
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章