2012-09-26 42 views
0

(我使用C#,VB.NET不)JMail的發送HTML格式的電子郵件,圖像變量未提交

Set jmail = Server.CreateObject("JMail.Message") 

jmail.AddRecipient "[email protected]", "Mr.Example" 
jmail.From = "[email protected]" 

jmail.Subject = "Here's some graphics!" 
jmail.Body = "A nice picture if you can read HTML-mail." 

' The return value of AddAttachment is used as a 
' reference to the image in the HTMLBody. 
contentId = jmail.AddAttachment("c:\myCoolPicture.gif") 

' 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>" 

' 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" 

jmail.Send("mailserver.mydomain.com") 

這是我能找到通過JMAIL發送HTML電子郵件的唯一例子。

但是,正如你在這裏看到的,這是一個圖像文件。

我的情況是我將生成一個圖像,並直接發送它而不保存爲一個文件。

那麼爲此我可以做些什麼嗎? 我真的不想保存它,然後把它然後將其刪除.....

非常感謝

+0

也許使用流,如下所示:[System.Drawing.Image流C#](http://stackoverflow.com/questions/1668469/system-drawing-image-to-stream-c-sharp)? – Tim

+0

@Tim使用.NET System.NET.Mail namespce,但正如我明確指出的那樣,我正在使用jmail。 – Franva

+0

實際上答案是使用System.Drawing.Image和System.IO - 它與電子郵件無關,只是一種獲取圖像而不在文件中的方式,除非我錯過了某些東西? – Tim

回答

0

似乎沒有別的選擇,只能將其保存爲一個文件,並將其發送,然後刪除它....

我會離開這個職位再看幾天,看看是否有解決此問題的可能辦法。

1

有一種方法...使用嵌入的base64 CSS3相似圖片:

.myImage {background: url(data:image/gif;base64,R0lGODlhBgASALM...)} 

和參考本在你的HTML代碼作爲一個DIV標籤。根本沒有文件需要保存。

相關問題