傳送圖片有3種方法:
- 附檔。
- 嵌入圖片。
- 寄送圖片連結。
'建立< img src="cid:xxx.jpg" />標籤串 Function ChartCID() ChartCID = "市場多空走勢:<br/ ><img src=""cid:市場多空走勢.jpg"" /><br/ >" & _ "大戶走勢:<br/ ><img src=""cid:大戶走勢.jpg"" /><br/ >" & _ "買賣力差走勢:<br/ ><img src=""cid:買賣力差走勢.jpg"" /><br/ >" End Function Sub 藉由Hotmail寄信() Dim Mail As CDO.Message Set Mail = New CDO.Message With Mail.Configuration.Fields .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp-mail.outlook.com" .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "white_5168@hotmail.com" .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "***********" .Update End With With Mail .Subject = "VBA透過Hotmail寄mail" .From = "white_5168@hotmail.com" .To = "white5168@gmail.com;white-5168@yahoo.com.tw;white_5168@hotmail.com" .CC = "white_5168@hotmail.com" .HTMLBody = ChartCID '指定插入圖片的實際位置 .AddRelatedBodyPart "C:\Users\Amin\Desktop\Pic\20160706\市場多空走勢.jpg", "市場多空走勢.jpg", 1 .AddRelatedBodyPart "C:\Users\Amin\Desktop\Pic\20160706\大戶走勢.jpg", "大戶走勢.jpg", 1 .AddRelatedBodyPart "C:\Users\Amin\Desktop\Pic\20160706\買賣力差走勢.jpg", "買賣力差走勢.jpg", 1 .HTMLBodyPart.Charset = "utf-8" .Send End With MsgBox "信件已寄出", vbInformation, "寄出" Set Mail = Nothing End Sub
程式碼說明:
第02~06行:建立< img src="cid:xxx.jpg" />標籤串。
第38~40行:指定插入圖片物件的實體位置。
執行結果:
參考資料: