使用SMTP协议发送邮件
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协议发送邮件的更多相关文章
- SMTP 协议发送邮件的整体过程
使用 SMTP 发送邮件_使用 SMTP 发送邮件_发送邮件_用户指南_邮件推送-阿里云 https://help.aliyun.com/knowledge_detail/51622.html 通过 ...
- 通过telnet使用smtp协议发送邮件
smtp协议是一个简单的邮件传输协议,利用它我们可以将邮件发送给别人,这里将通过telnet这个程序利用smtp协议从网易向gmail发送一封邮件 网上不少有说使用telnet发送邮件的文章,我也看过 ...
- java实现发送邮件服务器,SMTP协议发送邮件
1.采用SMTP的邮件发送协议.准备:在网易注册一个邮箱,进入设置开启SMTP/pop3协议 2.接下来就是java代码实现了,下面都有注释,就不多做解释了. public class mail { ...
- C语言利用SMTP协议发送邮件
#ifdef WIN32 #include <windows.h> #include <stdio.h> #else #include <stdio.h> #inc ...
- 使用java mail的网易smtp协议 发送邮件
package com.enation.newtest; import java.security.GeneralSecurityException; import java.util.Propert ...
- Java通过socket实现smtp协议发送邮件
import java.io.BufferedReader;import java.io.DataOutputStream;import java.io.IOException;import java ...
- QTP使用Smtp协议发送邮件
NameSpace = "http://schemas.microsoft.com/cdo/configuration/" Set Email = CreateObject(&qu ...
- C# 如何通过mailto标签和SMTP协议两种方式发送邮件
本文主要讲解如何通过如现mailto标签和SMTP协议两种方式发送邮件,下面就直入主题 方法一.通过mailto标签发送邮件 通过mailto不是正真意义上的发送邮件,它只是会自动调用我们本地默认的邮 ...
- Smtp协议与Pop3协议的简单实现
前言 本文主要介绍smtp与pop3协议的原理,后面会附上对其的简单封装与实现. smtp协议对应的RFC文档为:RFC821 smtp协议 SMTP(Simple Mail Transfer Pro ...
随机推荐
- python函数2(返回值、传递列表...)
python函数2(返回值.传递列表...) 1.返回值 1.1.返回简单的值 #返回简单值 def get_formatted_name(first_name,last_name): "& ...
- Codeforces_733_C
http://codeforces.com/problemset/problem/733/C 从后往前一个个b对应一组组a. #include<iostream> #include< ...
- Codeforces_460_B
http://codeforces.com/problemset/problem/460/B 枚举s(X). #include<cstdio> #include<iostream&g ...
- re模块 findall()详解
1. findall() 函数的2种表示形式 import re kk = re.compile(r'\d+') kk.findall('one1two2three3four4') #[1,2,3,4 ...
- hive命令
1.库命令:show databases; 查看所有库名select current_database(); 显示当前数据库:describe database publish; 查看某个库信息use ...
- 【算法】混合流体模拟demo
展示一个流体模拟算法的实现 地址:http://www.iqiyi.com/w_19rzs1anol.html 采用C++编写,Blender渲染. 截图 参考文献 REN, B., LI, C., ...
- BeautifulSoup入门
BeautifulSoup库入门 BeautifulSoup库的理解 BeautifulSoup库是解析.遍历.维护”标签树”的功能库 示例代码: from bs4 import BeautifulS ...
- frp内网穿透协助内网程序(如微信相关)开发
众所周知,在本机上开发微信相关的程序,很不方便,因为拨号IP随机,而且很多端口不支持,如80,443 所以,有必要使用一台外网主机中转. frp就可以解决此问题 安装环境,外网服务器:腾讯云,cent ...
- python 中列表 元组 字典 集合的区别
先看图片解释 (1)列表 什么是列表呢?我觉得列表就是我们日常生活中经常见到的清单.比如,统计过去一周我们买过的东西,把这些东西列出来,就是清单.由于我们买一种东西可能不止一次,所以清单中是允许有重复 ...
- html input元素的所有type属性
<input /> 属性 type="text" 输入框的类型为文本 type="password" 输入框的类型为密码 type="ra ...