最近发现我之前的程序不能用了。于是我想代替程序,于是找到MailKit了,我先试一下水。
using System;
using System.Text;
using System.Net.Mail;
using System.Net;namespace sendmail
{internal class Program{static void Main(string[] args){try{SmtpClient smtp = new SmtpClient("smtp.office365.com",587); smtp.Credentials = new NetworkCredential("yourmail@outlook.com", "yourpassword");smtp.UseDefaultCredentials = true;smtp.EnableSsl = true;smtp.DeliveryMethod = SmtpDeliveryMethod.Network;MailMessage content = new MailMessage();content.From = new MailAddress("yourmail@outlook.com");content.SubjectEncoding = Encoding.UTF8;content.BodyEncoding = Encoding.UTF8;content.IsBodyHtml = false;content.Priority = MailPriority.High;if (args.Length == 4 && args[0] == "-t"){//content.To.Add(new MailAddress(args[1]));//args[2];content.Subject = args[2];//args[3];content.Body = args[3];smtp.Send(content);}else{Console.OutputEncoding= Encoding.UTF8;Console.WriteLine("args参数输入有误!");}}catch (Exception ex){//Console.OutputEncoding = Encoding.UTF8;Console.WriteLine();Console.WriteLine(ex.Message);throw ex;}}}
}