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; }
}
}

使用SMTP协议发送邮件的更多相关文章

  1. SMTP 协议发送邮件的整体过程

    使用 SMTP 发送邮件_使用 SMTP 发送邮件_发送邮件_用户指南_邮件推送-阿里云 https://help.aliyun.com/knowledge_detail/51622.html 通过 ...

  2. 通过telnet使用smtp协议发送邮件

    smtp协议是一个简单的邮件传输协议,利用它我们可以将邮件发送给别人,这里将通过telnet这个程序利用smtp协议从网易向gmail发送一封邮件 网上不少有说使用telnet发送邮件的文章,我也看过 ...

  3. java实现发送邮件服务器,SMTP协议发送邮件

    1.采用SMTP的邮件发送协议.准备:在网易注册一个邮箱,进入设置开启SMTP/pop3协议 2.接下来就是java代码实现了,下面都有注释,就不多做解释了. public class mail { ...

  4. C语言利用SMTP协议发送邮件

    #ifdef WIN32 #include <windows.h> #include <stdio.h> #else #include <stdio.h> #inc ...

  5. 使用java mail的网易smtp协议 发送邮件

    package com.enation.newtest; import java.security.GeneralSecurityException; import java.util.Propert ...

  6. Java通过socket实现smtp协议发送邮件

    import java.io.BufferedReader;import java.io.DataOutputStream;import java.io.IOException;import java ...

  7. QTP使用Smtp协议发送邮件

    NameSpace = "http://schemas.microsoft.com/cdo/configuration/" Set Email = CreateObject(&qu ...

  8. C# 如何通过mailto标签和SMTP协议两种方式发送邮件

    本文主要讲解如何通过如现mailto标签和SMTP协议两种方式发送邮件,下面就直入主题 方法一.通过mailto标签发送邮件 通过mailto不是正真意义上的发送邮件,它只是会自动调用我们本地默认的邮 ...

  9. Smtp协议与Pop3协议的简单实现

    前言 本文主要介绍smtp与pop3协议的原理,后面会附上对其的简单封装与实现. smtp协议对应的RFC文档为:RFC821 smtp协议 SMTP(Simple Mail Transfer Pro ...

随机推荐

  1. 关于使用详解ASP.NET State Service

    ASP.NET State Service服务如果启动可以解决这个问题,它会生成一个aspnet_state.exe进程,这个就是Session信息的进程.只要这个进程在,就算是重启了IIS,站点的S ...

  2. 使用Apache服务器实现Nginx反向代理

    实验环境:centos7 注:因为本次实验在同一台服务器上,Apache与Nginx同为80端口,所以改Apache端口为60 1 配置Nginx服务器: 编辑Nginx配置文件,写入以下内容 loc ...

  3. C++:析构函数的调用时机

    结论:只有当类的某个实例化对象的构造函数执行完毕,而且当该对象退出作用域时,才会执行析构函数. 如果在执行构造函数的过程中抛出了异常,就不会调用析构函数 上测试代码: class Test { pub ...

  4. CentOS使用Postfix发送邮件

    1)配置hosts映射 [root@mail ~]# ifconfig ens33 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mt ...

  5. java架构之路-(微服务专题)feign的基本使用和nacos的配置中心

    上次回归: 上次我们说了ribbon的基本使用,包括里面的内部算法,算法的细粒度配置,还有我们自己如何实现我们自己的算法,主要还是一些基本使用的知识,还不会使用ribbon的小伙伴可以回去看一下上一篇 ...

  6. 【大白话系统】MySQL 学习总结 之 缓冲池(Buffer Pool) 如何支撑高并发和动态调整

    如果大家对我的 [大白话系列]MySQL 学习总结系列 感兴趣的话,可以点击关注一波. 一.上节回顾 在上节< 缓冲池(Buffer Pool) 的设计原理和管理机制>中,介绍了缓冲池整体 ...

  7. pytorch之 regression

    import torch import torch.nn.functional as F import matplotlib.pyplot as plt # torch.manual_seed(1) ...

  8. win 8.0.12

    一.下载 下载页面http://dev.mysql.com/downloads/mysql/ 选择系统平台后,点击download(根据系统选择64或32位) 二.配置 1.下载成功后,解压安装包到要 ...

  9. Visual C# 2015调用SnmpSharpNet库实现简单的SNMP元素查询

    一开始调研发现有几个SNMP的库, 一个是net-SNMP,这个好像是linux用的多 一个是微软自己的WinSNMP,这个没有例子,不太好操作 一个是SnmpSharpNet,这个有些例子比较好, ...

  10. Nginx简介入门

    买了极客时间上陶辉的Nginx核心知识100讲,正在学.链接 Nginx 4个组成部分 二进制可执行文件 nginx.conf 配置文件 access.log error.log nginx 版本 M ...