class Program
{
static void Main(string[] args)
{
if (args != null && args.Length > )
{
try
{
inputmodel obj = new inputmodel(args);
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = obj.SmtpHost;//如使用163的SMTP服务器发送邮件:"smtp.163.com";
client.UseDefaultCredentials = true;
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
client.Credentials = new System.Net.NetworkCredential(obj.FromMail, obj.FromPwd);//账号、密码(用授权码比较安全)
client.Port = ; System.Net.Mail.MailMessage Message = new System.Net.Mail.MailMessage();
Message.From = new System.Net.Mail.MailAddress(obj.FromMail);
foreach (var p in obj.ToMail.Split(','))
{
Message.To.Add(p);//收件人
Console.WriteLine(p);
}
Message.Subject = obj.Subject;//主题
Message.Body = obj.Body;//内容
Message.SubjectEncoding = System.Text.Encoding.UTF8;//主题编码
Message.BodyEncoding = System.Text.Encoding.UTF8;//内容编码
Message.Priority = System.Net.Mail.MailPriority.High;//邮件级别
Message.IsBodyHtml = true;
client.Send(Message);
Console.WriteLine("发送成功");
}
catch (Exception e)
{
Console.WriteLine($"error:{e.Message}");
} }
else
{
Console.WriteLine("必要参数如下:");
Console.WriteLine("-f FromMail");
Console.WriteLine("-t ToMail");
Console.WriteLine("-s Subject");
Console.WriteLine("-b Body");
Console.WriteLine("-h SmtpHost");
Console.WriteLine("-p FromPwd");
}
} private class inputmodel
{
public inputmodel(string[] args)
{
int i = -;
i = Array.FindIndex(args, o => o == "-f");
if (i != -)
{
this.FromMail = args[i + ];
}
i = Array.FindIndex(args, o => o == "-t");
if (i != -)
{
this.ToMail = args[i + ];
}
i = Array.FindIndex(args, o => o == "-s");
if (i != -)
{
this.Subject = args[i + ];
}
i = Array.FindIndex(args, o => o == "-b");
if (i != -)
{
this.Body = args[i + ];
}
i = Array.FindIndex(args, o => o == "-h");
if (i != -)
{
this.SmtpHost = args[i + ];
}
i = Array.FindIndex(args, o => o == "-p");
if (i != -)
{
this.FromPwd = args[i + ];
}
}
public string FromMail { get; set; }
public string ToMail { get; set; }
public string Body { get; set; }
public string Subject { get; set; }
public string FromPwd { get; set; }
public string SmtpHost { get; set; }
}
}

最新文章

  1. 开发ios的语言
  2. JavaScricp
  3. NSoperation用法详解及与GCD的比较
  4. mysql查看数据库
  5. review过去的10年
  6. 【学习整理】Tarjan:强连通分量+割点+割边
  7. Multi-source Replication
  8. 2015 NI 校招笔试机试面试
  9. 关于C函数的参数个数的问题
  10. poj1799---解析几何
  11. 【Ruby】Ruby的model学习——Active Record Associations
  12. iOS开发加快审核app
  13. WinForm 窗体之间相互嵌套
  14. mysql:The user specified as a definer ('xxx'@'%') does not exist 解决方法
  15. 为什么AI的翻译水平还远不能和人类相比?
  16. Install rapyuta client on Ubuntu14.04
  17. PHP 使用数字作为SESSION的Key,一刷新页面session丢失,Session消失,无法存储
  18. MySQL 支持的数据类型
  19. vue组件的使用和事件传递
  20. set的一些数学运算

热门文章

  1. supervisor管理tomcat
  2. python学习记录(四)
  3. uniapp单页面配置无导航栏
  4. ajax 原生js封装ajax [转]
  5. window10 vs2013 SIFTGPU
  6. 【OpenGL】LNK1104 无法打开文件“freeglutd.lib”
  7. 如何用Python实现do...while语句
  8. k8s系列---pod介绍
  9. ATTENTION NETWORK分析
  10. [WPF 自定义控件]在MenuItem上使用RadioButton