ASP采用Jmail發(fā)送普通附件和嵌入附件
當前位置:點晴教程→知識管理交流
→『 技術(shù)文檔交流 』
JMail發(fā)送郵件的例子都沒有寫如何發(fā)附件,或者沒有寫清如何發(fā)內(nèi)嵌的附件(比如把附件圖片嵌入到HTML信件里面)
郁悶到極的時候終于“柳暗花明”,噢yeah~~?。?! 其實最關(guān)鍵的就是這句要注釋掉 'JMail.ContentType = "text/html" (為什么要發(fā)內(nèi)嵌的附件圖片?因為如果是img src=網(wǎng)上的地址,在outlook等客戶端內(nèi)則顯示是難看的“X”,需要手動下載圖片) 本例子參考了Dimac(w3JMail官方)的樣例,文件地址: C:\Program Files\Dimac\w3JMail4\Examples\ASP\htmlimage.asp (安裝了Jmail的都有) 例子代碼: <% '************************************************* '* * '* Produced by Skyhe.Com * '* * '* Code Written by Kittow at 2005-11 * '* http://www.skyhe.com * '* Mail:kittow_AT_263.net * '* * '* * '************************************************* Set JMail = Server.CreateObject("JMail.Message") '是否將信頭編碼成iso-8859-1字符集. 缺省是True JMail.ISOEncodeHeaders = True 字串9 '如果JMail.silent設(shè)置為true,ErrorCode包含的是錯誤代碼 JMail.Silent = True '設(shè)置標題和內(nèi)容編碼,如果標題有中文,必須設(shè)定編碼為gb2312 JMail.Charset = "gb2312" 'JMail.ContentType = "text/html" '如果發(fā)內(nèi)嵌附件一定要注釋掉這行,重要! JMail.From = "web@mail.skyhe.com" ' 發(fā)送者地址 JMail.FromName = "Skyhe System" ' 發(fā)送者姓名 JMail.MailServerUserName = "web" ' 身份驗證的用戶名 JMail.MailServerPassword = "123456" ' 身份驗證的密碼 '加入新的收件人 JMail.AddRecipient "kittow@mail.skyhe.com", "Mr.Example" 'JMail.AddRecipientBCC Email '密件收件人的地址 'JMail.AddRecipientCC Email '郵件抄送者的地址 JMail.Subject = "圖片測試?。?!" JMail.Body = "A nice picture if you can read HTML-mail." '增加一個普通附件 JMail.AddAttachment(Server.MapPath("images/email.gif")) '增加一個嵌入式附件 ' The return value of AddAttachment is used as a 字串4 ' reference to the image in the HTMLBody. 'contentId = JMail.AddAttachment(Server.MapPath("images/email.gif")) Dim contentId contentId = JMail.AddAttachment("E:\images\email.gif") '只有HTML格式支持嵌入圖片附件,我們采用HTML格式的郵件內(nèi)容 ' As only HTML formatted emails can contain inline images ' we use HTMLBody and appendHTML JMail.HTMLBody = "<html><body><font color=""red"">Hi, here is a nice picture:</font><br>" JMail.appendHTML "<img src=""cid:" & contentId & """>" JMail.appendHTML "<br><br> good one huh?</body></html>" '如果對方信箱不支持HTML格式郵件,我們?nèi)孕枰o他一個友善的提示 ' But as not all mailreaders are capable of showing HTML emails ' we will also add a standard text body JMail.Body = "Too bad you can't read HTML-mail." JMail.appendText " There would have been a nice picture for you" 字串6 JMail.Send( "mail.skyhe.com" ) JMail.Close() Set JMail = Nothing %> 該文章在 2011/9/20 8:44:05 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |