Jmail發送郵件與帶附件亂碼解決辦法分享

來源:互聯網
上載者:User

 這篇文章主要介紹了Jmail發送郵件與帶附件亂碼解決辦法,有需要的朋友可以參考一下

Jamil發送郵件的具體用法: 首先,我們要先下載Jamil.dll的組件,然後添加引用using jmail,然後再本機或者伺服器上註冊一下 將jmail.dll拷貝到伺服器的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();         //設定字元集         jmMessage.Charset = "gb2312";         //寄件者郵箱地址         jmMessage.From = senderMail;         //寄件者姓名         jmMessage.FromName = sender;         //設定主題         jmMessage.Subject = subject;         //設定內容         jmMessage.Body = content;         // 設定收件者郵箱         jmMessage.AddRecipient(receiver, "", "");         // 設定登陸郵箱的使用者名稱和密碼         jmMessage.MailServerUserName = "ss";         jmMessage.MailServerPassWord = "ss";         //設定smtp伺服器位址         if (jmMessage.Send("smtp.163.com", false))        {             Response.Write("<script>alert('發送成功')</script>");         }         else             Response.Write("<script>alert('www.jb51.net發送失敗')</script>");     }   上面就是Jmail的具體用法! 我想放一個附件如下 代碼如下:jmail.AddAttachment(“c:autoexec.bat”) jmail.AddAttachment(“myImage.gif”,TRUE)   結果出現如下錯誤 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: 網上找瞭解決方法:  代碼如下:AddAttachment(FileName, isInline, ContentType) :   String為郵件添加一個檔案型的附件。如果Inline 屬性被設定為true,這個附件就是一個可嵌入的附件,使用addAttachment()方法可返回content id,這在發送HTML 郵件時是非常有用的。 例:   代碼如下:jmail.AddAttachment(“c:autoexec.bat”) jmail.AddAttachment(“myImage.gif”,TRUE)  可嵌入的附件 2.AddURLAttachment(bstrURL, bstrAttachAs, isInline, bstrAuth) : String從指定的URL 下載檔案並添加為附件。第二個參數“AttachAs”用來更改添加為附件的檔案的檔案名稱,如果Inline 屬性被設定為true,這個附件就是一個可嵌入的附件,使用ddAttachment()方法可返回content id,這在發送HTML 郵件時是非常有用的。最後一個參數為可選項,是當伺服器需要身分識別驗證時使用的。 例   代碼如下:jmail.AddURLAttachment(“w3jmail4.exe”,”w3jmail4.exe”)jmail.AddURLAttachment”w3jmail4.exe”, “w3jmail4.exe”,false, “myUserName:myPassword”)jmail.AddURLAttachment”dimaclogo.gif”,”dimaclogo.gif”,true )   測了一下,好像跟兩個方法沒什麼關係。後來在網上有人說把Message.ContentType =”text/html”設定去掉(就是不要去設定ContentType屬性),試了一下,還真發送成功了 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.