Jmail發(fā)送郵件與帶附件亂碼解決辦法分享
Jamil發(fā)送郵件的具體用法:
首先,我們要先下載Jamil.dll的組件,然后添加引用using jmail,然后再本機或者服務(wù)器上注冊一下
將jmail.dll拷貝到服務(wù)器的system32目錄下,開始-運行-cmd-輸入regsvr32 jmail.dll,注冊成功,然后寫代碼
代碼如下(方法)
using jmail;
protected void sendMail(String sender, String senderMail, String receiver, String subject, String content)
{
jmail.MessageClass jmMessage = new jmail.MessageClass();
//設(shè)置字符集
jmMessage.Charset = "gb2312";
//發(fā)件人郵箱地址
jmMessage.From = senderMail;
//發(fā)件人姓名
jmMessage.FromName = sender;
//設(shè)置主題
jmMessage.Subject = subject;
//設(shè)置內(nèi)容
jmMessage.Body = content;
// 設(shè)置收件人郵箱
jmMessage.AddRecipient(receiver, "", "");
// 設(shè)置登陸郵箱的用戶名和密碼
jmMessage.MailServerUserName = "ss";
jmMessage.MailServerPassWord = "ss";
//設(shè)置smtp服務(wù)器地址
if (jmMessage.Send("smtp.163.com", false))
{
Response.Write("<script>alert('發(fā)送成功')</script>");
}
else
Response.Write("<script>alert('www.dhdzp.com發(fā)送失敗')</script>");
}
上面就是Jmail的具體用法!
我想放一個附件如下
jmail.AddAttachment(“c:autoexec.bat”)
jmail.AddAttachment(“myImage.gif”,TRUE)
結(jié)果出現(xiàn)如下錯誤
This is a multipart message in MIME format. —-NEXT_BM_AEB3968967D044DC9E208D04088C60B4 Content-Type: text/html; charset=”GB2312″ Content-Transfer-Encoding: Quoted-Printable sdfdd —-NEXT_BM_AEB3968967D044DC9E208D04088C60B4 Content-Type: application/octet-stream; name=”=?GB2312?Q?12d95384-576f-424f-bf15-f8e2397e2791=2EJPG?=” Content-Transfer-Encoding: base64 Content-Description: =?GB2312?Q?12d95384-576f-424f-bf15-f8e2397e2791=2EJPG?= Content-Disposition: inline; filename=”=?GB2312?Q?12d95384-576f-424f-bf15-f8e2397e2791=2EJPG?=” Content-ID:
網(wǎng)上找了解決方法:
AddAttachment(FileName, isInline, ContentType) :
String為郵件添加一個文件型的附件。如果Inline 屬性被設(shè)置為true,這個附件就是一個可嵌入的附件,使用addAttachment()方法可返回content id,這在發(fā)送HTML 郵件時是非常有用的。
例:
jmail.AddAttachment(“c:autoexec.bat”)
jmail.AddAttachment(“myImage.gif”,TRUE)
可嵌入的附件
2.AddURLAttachment(bstrURL, bstrAttachAs, isInline, bstrAuth) : String從指定的URL 下載文件并添加為附件。第二個參數(shù)“AttachAs”用來更改添加為附件的文件的文件名,如果Inline 屬性被設(shè)置為true,這個附件就是一個可嵌入的附件,使用ddAttachment()方法可返回content id,這在發(fā)送HTML 郵件時是非常有用的。最后一個參數(shù)為可選項,是當(dāng)服務(wù)器需要身份驗證時使用的。
例
jmail.AddURLAttachment(“w3jmail4.exe”,”w3jmail4.exe”)
jmail.AddURLAttachment”w3jmail4.exe”, “w3jmail4.exe”,false, “myUserName:myPassword”)jmail.AddURLAttachment”dimaclogo.gif”,”dimaclogo.gif”,true )
測了一下,好像跟兩個方法沒什么關(guān)系。后來在網(wǎng)上有人說把Message.ContentType =”text/html”設(shè)置去掉(就是不要去設(shè)置ContentType屬性),試了一下,還真發(fā)送成功了
相關(guān)文章
asp.net 2.0中利用Ajax2.0實現(xiàn)JSON傳送大量頁面數(shù)據(jù)
本人遇到一個程序頁面,要有很大量的數(shù)據(jù)進行交互操作。2010-03-03
動態(tài)組合SQL語句方式實現(xiàn)批量更新的實例
動態(tài)組合SQL語句方式實現(xiàn)批量更新的實例,需要的朋友可以參考一下2013-03-03
asp.NET中實現(xiàn)文件的壓縮和解壓(3種方式)
本篇文章主要介紹了asp.NET中實現(xiàn)文件的壓縮和解壓,這里整理了詳細的代碼,有需要的小伙伴可以參考下。2016-11-11
asp.net DropDownList 三級聯(lián)動下拉菜單實現(xiàn)代碼
asp.net DropDownList 三級聯(lián)動下拉菜單效果代碼,需要的朋友可以參考下。2009-12-12
asp.net 根據(jù)漢字的拼音首字母搜索數(shù)據(jù)庫(附 LINQ 調(diào)用方法)
我們經(jīng)常需要使用拼音首字母來檢索數(shù)據(jù)庫,特別是應(yīng)用于醫(yī)院、商店等行業(yè)軟件中。譬如搜索“zgr”就可以搜索所有包含“中國人”的記錄。那么如果來實現(xiàn)才能即高效又方便呢?2010-04-04

