博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#收发邮件(Jmail+Professional+v4.4+特别版)
阅读量:7118 次
发布时间:2019-06-28

本文共 4256 字,大约阅读时间需要 14 分钟。

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using jmail; namespace WindowsApplication12 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent(); } private void buttonX1_Click(object sender, EventArgs e) {
jmail.Message Jmail = new jmail.Message(); DateTime t = DateTime.Now; String Subject = " From EMail .net"; String body = "你好科学12:15"; String FromEmail = "lcqyue@163.com"; String ToEmail = "qanholas@163.com"; //Silent属性:如果设置为true,JMail不会抛出例外错误. JMail. Send( () 会根据操作结果返回true或false Jmail.Silent = true; //Jmail创建的日志,前提loging属性设置为true Jmail.Logging = true; //字符集,缺省为"US-ASCII" Jmail.Charset = "GB2312"; //信件的contentype. 缺省是"text/plain") : 字符串如果你以HTML格式发送邮件, 改为"text/html"即可。 Jmail.ContentType = "text/html"; //添加收件人 Jmail.AddRecipient(ToEmail, "", ""); Jmail.From = FromEmail; //发件人邮件用户名 Jmail.MailServerUserName = "lcqyue"; //发件人邮件密码 Jmail.MailServerPassWord = "s"; //设置邮件标题 Jmail.Subject = Subject; //邮件添加附件,(多附件的话,可以再加一条Jmail.AddAttachment( "c://test.jpg",true,null);)就可以搞定了。[注]:加了附件,讲把上面的Jmail.ContentType="text/html";删掉。否则会在邮件里出现乱码。 // Jmail.AddAttachment("c://test.jpg", true, null); //邮件内容 Jmail.Body = body + t.ToString(); //Jmail发送的方法 Jmail.Send("smtp.163.com", false); Jmail.Close(); } /**/ /// /// 利用Jmail接收邮件 /// private void ReciveByJmail() {
/**/ ///建立收邮件对象 jmail.POP3Class popMail = new POP3Class(); /**/ ///建立邮件信息接口 jmail.Message mailMessage; /**/ ///建立附件集接口 jmail.Attachments atts; /**/ ///建立附件接口 jmail.Attachment att; try {
popMail.Connect("qanholas", "s", "pop3.163.com", 110); /**/ ///如果收到邮件 //if (0 < popMail.Count) //{
/**/ ///根据取到的邮件数量依次取得每封邮件 for (int i = 1; i <= popMail.Count; i++) {
/**/ ///取得一条邮件信息 mailMessage = popMail.Messages[i]; /**/ ///取得该邮件的附件集合 atts = mailMessage.Attachments; /**/ ///设置邮件的编码方式 mailMessage.Charset = "GB2312"; /**/ ///设置邮件的附件编码方式 mailMessage.Encoding = "Base64"; /**/ ///是否将信头编码成iso-8859-1字符集 mailMessage.ISOEncodeHeaders = false; /**/ ///邮件的优先级 // txtpriority.Text = mailMessage.Priority.ToString(); /**/ ///邮件的发送人的信箱地址 // txtSendMail.Text = mailMessage.From; /**/ ///邮件的发送人 // txtSender.Text = mailMessage.FromName; /**/ ///邮件主题 // txtSubject.Text = mailMessage.Subject; /**/ ///邮件内容 // txtBody.Text = mailMessage.Body; MessageBox.Show( mailMessage.HTMLBody); /**/ ///邮件大小 // txtSize.Text = mailMessage.Size.ToString(); for (int j = 0; j < atts.Count; j++) {
/**/ ///取得附件 att = atts[j]; /**/ ///附件名称 string attname = att.Name; /**/ ///上传到服务器 // att.SaveToFile("e://attFile//" + attname); } } // panMailInfo.Visible = true; att = null; atts = null; //} //else //{
// MessageBox.Show("没有新邮件!"); //} popMail.DeleteMessages(); popMail.Disconnect(); popMail = null; } catch {
MessageBox.Show("Warning!请检查邮件服务器的设置是否正确!"); } } private void buttonX2_Click(object sender, EventArgs e) {
ReciveByJmail(); } } }

转载地址:http://yxnel.baihongyu.com/

你可能感兴趣的文章
SoapUI Pro Project Solution Collection –Easy develop Groovy Script to improve SoapUI ability
查看>>
Windows 8实用窍门系列:9.Windows 8中使用FlipView
查看>>
(cljs/run-at (JSVM. :all) "一次说白DataType、Record和Protocol")
查看>>
需要友元的原因及使用
查看>>
hadoop-0.20.1+120 hive-0.3.99.1+0 试用hwi(hive web interface
查看>>
8.2. Pylons
查看>>
1040. Longest Symmetric String (25)
查看>>
全国主要城市不同日照标准的间距系数
查看>>
python网络爬虫(一):网络爬虫科普与URL含义
查看>>
工作了一个星期各位一定累了吧,那我们一起来表单验证一番吧!
查看>>
UVA 11732 - strcmp() Anyone?(Trie)
查看>>
java遍历hashMap、hashSet、Hashtable
查看>>
tcpdump
查看>>
如何注入值到Spring bean属性
查看>>
xm list源码分析
查看>>
PHPStorm 调式JS /同时调式PHP和jS
查看>>
JavaScript中的shift()、unshift()和pop()函数
查看>>
css案例学习之div与span的区别
查看>>
大话PHP缓存头
查看>>
【Java学习笔记之三十一】详解Java8 lambda表达式
查看>>