MailKit系列之转发电子邮件
原文:http://www.it1352.com/429181.html
问题
我尝试通过MailKit访问一个IMAP账号,我设法下载邮件(作为的MimeMessage),并在某些时候我需要转发给其他帐户。
展示原始邮件的所有信息(不会忽略,标题,正文内容等)的最佳方式是什么?
解决方案
说“转发”时,不同的人意味着不同的想法,所以我想我会提供答案的不同含义的我能想到的。
1.转发(重发)无任何变化的消息
var message = FetchMessageFromImapServer (); using (var client = new SmtpClient ()) {
client.Connect ("smtp.example.com", , true);
client.Authenticate ("username", "password"); var sender = new MailboxAddress ("My Name", "username@example.com");
var recipients = new [] { new MailboxAddress ("John Smith", "john@smith.com") }; // This version of the Send() method uses the supplied sender and
// recipients rather than getting them from the message's headers.
client.Send (message, sender, recipients); client.Disconnect (true);
}
通常人们并不意味着这种类型的“转发”,虽然。如果他们想重新发送,通常他们会用重发的一个方法。
2.转发(重发)消息的标准方法
var message = FetchMessageFromImapServer (); // clear the Resent-* headers in case this message has already been Resent...
message.ResentSender = null;
message.ResentFrom.Clear ();
message.ResentReplyTo.Clear ();
message.ResentTo.Clear ();
message.ResentCc.Clear ();
message.ResentBcc.Clear (); // now add our own Resent-* headers...
message.ResentFrom.Add (new MailboxAddress ("MyName", "username@example.com"));
message.ResentReplyTo.Add (new MailboxAddress ("MyName", "username@example.com"));
message.ResentTo.Add (new MailboxAddress ("John Smith", "john@smith.com"));
message.ResentMessageId = MimeUtils.GenerateMessageId ();
message.ResentDate = DateTimeOffset.Now; using (var client = new SmtpClient ()) {
client.Connect ("smtp.example.com", , true);
client.Authenticate ("username", "password"); // The Send() method will use the Resent-From/To/Cc/Bcc headers if
// they are present.
client.Send (message); client.Disconnect (true);
}
3.以一个新的消息转发
有些邮件客户端可能会将整个邮件作为新的消息的方式转发邮件。
var messageToForward = FetchMessageFromImapServer (); // construct a new message
var message = new MimeMessage ();
message.From.Add (new MailboxAddress ("MyName", "username@example.com"));
message.ReplyTo.Add (new MailboxAddress ("MyName", "username@example.com"));
message.To.Add (new MailboxAddress ("John Smith", "john@smith.com")); // now to create our body...
var builder = new BodyBuilder ();
builder.TextBody = "Hey John,\r\n\r\nHere's that message I was telling you about...\r\n";
builder.Attachments.Add (new MessagePart { Message = messageToForward }); message.Body = builder.ToMessageBody (); using (var client = new SmtpClient ()) {
client.Connect ("smtp.example.com", , true);
client.Authenticate ("username", "password"); client.Send (message); client.Disconnect (true);
}
MailKit系列之转发电子邮件的更多相关文章
- MailKit系列之附件分离
本文主要谈谈实现思路,不提供完整代码 一.分离基础 1.MIME邮件的multipart类型 引用文章:https://blog.csdn.net/wangyu13476969128/article/ ...
- MailKit系列之---查询SearchQuery
对于邮件的唯一Id查询,由于MailKit提供了大量的方法,无法完全讲解完全,所以这里只选择几个来介绍. MailKit通过方法folder.Search来查询邮件的唯一Id,参数是一个SearchQ ...
- redis 系列,这里转发别人博客, 和常用命令
https://blog.csdn.net/qq_35433716/category_7944890.html 常用命令: https://www.cnblogs.com/mznsndy/p/1395 ...
- EXCHANGE上冒充任意用户--Exchange Server权限提升漏洞(CVE-2018-8581)分析
0x00 前言 这是我们2018年Top 5趣案系列中的第三个案例.这些漏洞都有一些因素使它们从今年发布的大约1,400个报告中脱颖而出.今天我们将分析一个Exchange漏洞,它允许任何经过身份验证 ...
- 《Linux就该这么学》第二期视频
Linux就该这么学--第二期学习笔记... ------------- 你的未来取决于你现在点点滴滴的努力 需要用到的一些工具: Vm11激活码 ---------- root在Linux系统中相当 ...
- ASP.NET 网站管理工具
ylbtech-Miscellaneos:ASP.NET 网站管理工具 1. 网站管理工具概述返回顶部 网站管理工具概述 介绍 使用网站管理工具,可以通过一个简单的 Web 界面来查看和管理网站配置. ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON DirectShow (Delphi Prism)
zw版[转发·台湾nvp系列Delphi例程]HALCON DirectShow (Delphi Prism) namespace DirectShow_Prism;interfaceuses Sys ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON HImage与Bitmap格式转换
zw版[转发·台湾nvp系列Delphi例程]HALCON HImage与Bitmap格式转换 (Delphi Prism)namespace HImage_Bitmap_Prism;interfac ...
- zw版【转发·台湾nvp系列Delphi例程】.NET调用HALCON COM控件内存释放模式
zw版[转发·台湾nvp系列Delphi例程].NET调用HALCON COM控件内存释放模式 ------------------------------------方法一 :Imports Sys ...
随机推荐
- 【递归】hex2dec
自己捉摸了好久,由于不熟悉. #include <stdio.h> int dec2hex(char *p); int base; int num; int main(void) { ch ...
- 证明与计算(3): 二分决策图(Binary Decision Diagram, BDD)
0x01 布尔代数(Boolean algebra) 大名鼎鼎鼎的stephen wolfram在2015年的时候写了一篇介绍George Boole的文章:George Boole: A 200-Y ...
- MySQL之执行流程
最近开始在学习mysql相关知识,自己根据学到的知识点,根据自己的理解整理分享出来,本篇文章会分析下一个sql语句在mysql中的执行流程,包括sql的查询在mysql内部会怎么流转,sql语句的更新 ...
- 【zabbix教程系列】三、zabbix 3.4 在centos 7 上安装详细步骤
一.环境准备 [root@ltt01 ~]# ip a : lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN qlen ...
- Python——模块——linecache(对文本行的随机访问)
一.模块的作用 linecache模块允许它获取Python资源文件的任一行. 二.模块函数 (1)linecache. getline(filename, lineno, module_global ...
- Tutorial: Create a Windows Machine Learning UWP application (C#)
In this tutorial, we'll build a simple Universal Windows Platform application that uses a trained ma ...
- 用ES6创建一个简单工厂模式
1 什么是工厂模式? 工厂模式是用来创建对象的一种最常用的设计模式.我们不暴露创建对象的具体逻辑,而是将将逻辑封装在一个函数中,那么这个函数就可以被视为一个工厂.工厂模式根据抽象程度的不同可以分为:简 ...
- 【pytorch】pytorch-LSTM
pytorch-LSTM() torch.nn包下实现了LSTM函数,实现LSTM层.多个LSTMcell组合起来是LSTM. LSTM自动实现了前向传播,不需要自己对序列进行迭代. LSTM的用到的 ...
- Glide和Picasso的区别
首先简单的介绍下两个库的出身: Picasso是Square公司出品的一款非常优秀的开源图片加载库Glide是由Google开发,基于 Picasso,依然有保存了Picasso的简洁风格,但是在此做 ...
- 调试ucosii_pendsv中断函数有感
发现自己的代码的意思和自己理解的意思有不相同的时候,自己先用printf打印输出分析 当发现是自己那一个知识点没有掌握好时,自己用其他的C编译器,仿写用到的知识点的程序,然后掌握该知识点. 最后实在找 ...