亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

.net發送郵件的一些技巧

2019-11-18 16:44:06
字體:
來源:轉載
供稿:網友
用System.Web.Mail發送郵件,適用于.net1.1,.net2.0請用System.Net.Mail

先引用System.Web
1,發送簡單郵件
[ C# ]
MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "you@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
SmtpMail.SmtpServer = "localhost"; //your real server goes here
SmtpMail.Send( mail );

[ VB.NET ]
Dim mail As New MailMessage()
mail.To = "me@mycompany.com"
mail.From = "you@yourcompany.com"
mail.Subject = "this is a test email."
mail.Body = "this is my test email body"
SmtpMail.SmtpServer = "localhost" 'your real server goes here
SmtpMail.Send(mail)

這里的smtpserver只能是那些不需要驗證的smtp服務器,像126,sina,yahoo等等的郵箱,都需要驗證,所以不能用。用這些郵箱發信后面會講到


2,發送Html郵件
[ C# ]
MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "you@yourcompany.com";
mail.Subject = "this is a test email.";
mail.BodyFormat = MailFormat.Html;
mail.Body = "this is my test email body.<br><b>this part is in bold</b>";
SmtpMail.SmtpServer = "localhost"; //your real server goes here
SmtpMail.Send( mail );


[ VB.NET ]
Dim mail As New MailMessage()
mail.To = "me@mycompany.com"
mail.From = "you@yourcompany.com"
mail.Subject = "this is a test email."
mail.BodyFormat = MailFormat.Html
mail.Body = "this is my test email body.<br><b>this part is in bold</b>"
SmtpMail.SmtpServer = "localhost" 'your real server goes here
SmtpMail.Send(mail)

3,發送附件
[ C# ]
MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "you@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body.";
MailAttachment attachment = new MailAttachment( Server.MapPath( "test.txt" ) ); //create the attachment
mail.Attachments.Add( attachment ); //add the attachment
SmtpMail.SmtpServer = "localhost"; //your real server goes here
SmtpMail.Send( mail );

[ VB.NET ]
Dim mail As New MailMessage()
mail.To = "me@mycompany.com"
mail.From = "you@yourcompany.com"
mail.Subject = "this is a test email."
mail.Body = "this is my test email body."
Dim attachment As New MailAttachment(Server.MapPath("test.txt")) 'create the attachment
mail.Attachments.Add(attachment) 'add the attachment
SmtpMail.SmtpServer = "localhost" 'your real server goes here
SmtpMail.Send(mail)

4,修改發件人和收件人的名稱
比如發件人的地址是abc@126.com,我們用Outlook收到信,From一欄里將直接顯示abc@126.com.
能不能在From一欄里顯示友好一點的名字呢?
比如顯示Tony Gong

方法如下:
[ C# ]
MailMessage mail = new MailMessage();
mail.To = "/"John/" <me@mycompany.com>";
mail.From = "/"Tony Gong/" <you@yourcompany.com>";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body.";
SmtpMail.SmtpServer = "localhost"; //your real server goes here
SmtpMail.Send( mail );


[ VB.NET ]
Dim mail As New MailMessage()
mail.To = """John"" <me@mycompany.com>"
mail.From = """Tony Gong"" <you@yourcompany.com>"
mail.Subject = "this is a test email."
mail.Body = "this is my test email body."
SmtpMail.SmtpServer = "localhost" 'your real server goes here
SmtpMail.Send(mail)

5,發送給多人
[ C# ]
MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com;him@hiscompany.com;her@hercompany.com";
mail.From = "you@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body.";
SmtpMail.SmtpServer = "localhost"; //your real server goes here
SmtpMail.Send( mail );

[ VB.NET ]
Dim mail As New MailMessage()
mail.To = "me@mycompany.com;him@hiscompany.com;her@hercompany.com"
mail.From = "you@yourcompany.com"
mail.Subject = "this is a test email."
mail.Body = "this is my test email body."
SmtpMail.SmtpServer = "localhost" 'your real server goes here
SmtpMail.Send(mail)

6,用需要Smtp驗證的郵箱發信
現在為了防止垃圾郵件,絕大部分Smtp服務器需要驗證了
發信方法如下:
[ C# ]
 MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "abc@126.com";
mail.Subject = "this is a test email.";
mail.Body = "Some text goes here";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "abc"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassWord", "your password"); //set your password here

SmtpMail.SmtpServer = "smtp.126.com"; //your real server goes here
SmtpMail.Send( mail );




[ VB.NET ]

Dim mail As New MailMessage()
mail.To = "me@mycompany.com"
mail.From = "abc@126.com"
mail.Subject = "this is a test email."
mail.Body = "Some text goes here"
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "abc") 'set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "Your Password") 'set your password here
SmtpMail.SmtpServer = "smtp.126.com" 'your real server goes here
SmtpMail.Send(mail)



7,修改smtp服務器的端口,以及使用SSL加密
大部分smtp服務器的端口是25,但有些卻不是
同時,絕大部分Smtp服務器不需要SSL登陸,有些卻需要
比如Gmail,smtp端口是:465,同時支持SSL
代碼如下:

[ C# ]

MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "abc@126.com";
mail.Subject = "this is a test email.";
mail.Body = "Some text goes here";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "abc"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "your password"); //set your password here

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport",465);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
SmtpMail.SmtpServer = "smtp.126.com"; //your real server goes here
SmtpMail.Send( mail );








[ VB.NET ]


Dim mail As New MailMessage()
mail.To = "me@mycompany.com"
mail.From = "abc@126.com"
mail.Subject = "this is a test email."
mail.Body = "Some text goes here"
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "abc") 'set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "Your Password") 'set your password here

mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport",465)
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true")

SmtpMail.SmtpServer = "smtp.126.com" 'your real server goes here
SmtpMail.Send(mail)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
另类专区欧美制服同性| 亚洲一区二区三区在线免费观看| 中文国产成人精品| 国产精自产拍久久久久久蜜| 亚洲一区二区三区香蕉| 日韩中文字幕免费看| 国产精品三级网站| 成人性生交大片免费看小说| 国产成人激情视频| 欧美成人午夜剧场免费观看| 日韩在线视频线视频免费网站| 欧美激情啊啊啊| 亚洲精品视频免费在线观看| 国产精品国产三级国产aⅴ浪潮| 欧美日韩免费观看中文| 欧美成年人视频网站欧美| 亚洲精品一区二区在线| 成人黄色av网站| 91精品国产亚洲| 国产亚洲aⅴaaaaaa毛片| 成年人精品视频| 国产午夜精品麻豆| 韩国美女主播一区| 亚洲电影免费观看高清完整版| 亚洲福利在线观看| 日韩精品在线免费| 深夜福利91大全| 96sao精品视频在线观看| 久久久精品美女| 日韩高清a**址| 亚洲成av人影院在线观看| 伊人精品在线观看| 日韩精品一区二区三区第95| 日韩中文字幕精品视频| 精品国产一区二区三区久久| 亚洲欧美中文另类| 久久精品国亚洲| 国产狼人综合免费视频| 亚洲国产精品yw在线观看| 久久久久久久久国产精品| 久久久成人av| 日韩在线播放一区| 中文字幕最新精品| 富二代精品短视频| 亚洲第一色中文字幕| 国产精品扒开腿爽爽爽视频| 亚洲精品永久免费| 精品久久久久久中文字幕一区奶水| 成人精品视频99在线观看免费| 麻豆一区二区在线观看| 久久久亚洲网站| 久久精品国产久精国产一老狼| 久久频这里精品99香蕉| 岛国av一区二区三区| 91久久夜色精品国产网站| 国产亚洲视频在线| 91福利视频在线观看| 亚洲精品黄网在线观看| 日韩av电影免费观看高清| 韩国精品久久久999| 久久久亚洲精品视频| 久久久久国色av免费观看性色| 色午夜这里只有精品| 欧美亚洲另类激情另类| 日韩在线视频免费观看高清中文| 亚洲性生活视频在线观看| 亚洲免费伊人电影在线观看av| 久久人体大胆视频| 亚洲bt欧美bt日本bt| 亚洲成人久久电影| 精品自拍视频在线观看| 国产欧美日韩免费看aⅴ视频| 欧美性xxxxx极品| 精品久久久久久久久久久| 亚洲免费成人av电影| 日韩中文字幕不卡视频| 国产精品极品美女在线观看免费| 性色av一区二区三区免费| 国产激情综合五月久久| 91精品国产综合久久香蕉| 欧美日韩成人在线视频| 欧美成人精品xxx| 中文字幕在线看视频国产欧美在线看完整| 97视频国产在线| 欧美精品videos另类日本| 69**夜色精品国产69乱| 亚洲色图13p| 中文.日本.精品| 欧美老女人bb| 精品久久久久久久久久| 欧美性猛交丰臀xxxxx网站| 日韩风俗一区 二区| 中文在线资源观看视频网站免费不卡| 久久精视频免费在线久久完整在线看| 超碰97人人做人人爱少妇| 国产999精品久久久| 久久九九热免费视频| 日韩国产高清污视频在线观看| 一个人www欧美| 欧美老少配视频| 国产成人精品免费视频| 国产成人+综合亚洲+天堂| 国产精品av免费在线观看| 久久国产一区二区三区| www.欧美精品| 91久久综合亚洲鲁鲁五月天| 亚洲国产精品悠悠久久琪琪| 精品国产精品自拍| 亚洲色图25p| 中文字幕日韩av综合精品| 2018中文字幕一区二区三区| 97婷婷大伊香蕉精品视频| 亚洲精品视频网上网址在线观看| 日本一区二区三区四区视频| 日韩视频永久免费观看| 欧美人交a欧美精品| 亚洲电影av在线| 热久久免费国产视频| 亚洲欧洲在线播放| 美女扒开尿口让男人操亚洲视频网站| 一本一本久久a久久精品牛牛影视| 国产自摸综合网| 国内偷自视频区视频综合| 欧美成在线视频| 欧美精品制服第一页| 欧美巨乳在线观看| 国产亚洲精品成人av久久ww| 国产精品老女人精品视频| 国产日韩欧美电影在线观看| 欧美国产亚洲精品久久久8v| 久久大大胆人体| 色与欲影视天天看综合网| 日韩在线观看免费| www国产精品视频| 欧美一区二三区| 精品国产鲁一鲁一区二区张丽| 久久精品这里热有精品| 91精品国产综合久久久久久久久| 久久精品国产一区二区三区| 国产日本欧美在线观看| 亚洲欧美制服第一页| 久久久久久国产精品三级玉女聊斋| 国产一区二区美女视频| 欧美激情中文字幕乱码免费| 亚洲开心激情网| 亚洲欧美中文字幕在线一区| 欧美性极品xxxx娇小| 尤物99国产成人精品视频| 日韩在线观看免费高清完整版| 欧美一区二区视频97| 亚洲精品久久久久久久久久久| 国产精品精品国产| 亚洲国产一区二区三区四区| 亚洲高清久久久久久| 91成人天堂久久成人| 欧美日韩国产中字| 国产亚洲精品日韩| 国产精品美女av| 国产美女久久精品香蕉69| 亚洲最新在线视频| 欧美俄罗斯性视频| 91精品国产色综合久久不卡98| 精品久久久久久久久久ntr影视| 一本色道久久综合狠狠躁篇怎么玩|