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. LUAMD5加密

    md5里的方法: C:\Windows\System32>lua Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio > require( ...

  2. Magicodes.IE在Docker中使用

    Magicodes.IE在Docker中使用 更新日志 2019.02.13 [Nuget]版本更新到2.0.2 [导入]修复单列导入的Bug,单元测试"OneColumnImporter_ ...

  3. uml图六种箭头的含义

    转:https://blog.csdn.net/wglla/article/details/52225571 在看一些技术博客的时候,经常会见到博客里画上很多uml图.因为经常会被这几种表达关系的箭头 ...

  4. CCF_201312-4_有趣的数

    dp题,dp[i][j]代表i位数,j状态的数量.其中,j 的状态表示值有6种. 0 1 2     √ j = 0 3 01 02   √ j = 1 03 12 13 23   √ j = 2 0 ...

  5. Codeforces_478_C

    http://codeforces.com/problemset/problem/478/C 水. #include<stdio.h> int main() { long long a,b ...

  6. RF-ui自动化

    1.关于时间等待 Wait Until Keyword Succeeds      3x      300ms       Wait Until Element Is Visible      ${x ...

  7. gRPC in ASP.NET Core 3.x - gRPC 简介

    gRPC的结构 在我们搭建gRPC通信系统之前,首先需要知道gRPC的结构组成. 首先,需要一个server(服务器),它用来接收和处理请求,然后返回响应. 既然有server,那么肯定有client ...

  8. centos系统重装python或yum 报There was a problem importing one of the Python modules required to run yum. The error leading to this problem was:错误

    sudo vim /usr/bin/yum #修个python所在的路径,例如 #/usr/local/bin/python2.6 或 /usr/local/bin/python2.7要原本你的系统原 ...

  9. C语言RH850 F1KM serial bootloader和C#语言bootloader PC端串口通信程序

    了解更多关于bootloader 的C语言实现,请加我QQ: 1273623966 (验证信息请填 bootloader),欢迎咨询或定制bootloader(在线升级程序). 今天我要介绍的RH85 ...

  10. Day1前端学习之路——概述

    终于下定决心要好好学习前端知识了,以后会把学习过程中的一些随笔记录在这里.HTML.CSS.JavaScript这三大前端语言在大三的时候就有所接触,但是学习的不够深入,这一次希望能够坚持下去. 学习 ...