私はこれを厳密に検索しましたが、これを動作させることはできません。私は画像が電子メールの本文に埋め込まれているvb.netアプリケーション内から電子メールを送信しようとしています。私は添付ファイルとして動作するようになるが、Outlookやその他の電子メールクライアントでは、イメージは表示されません。画像はローカルに保存されており、その画像と何か関係があるのだろうかと思います。最初に文字列内に画像を追加しようとしましたが、うまくいきませんでした。vb.netから電子メールの本文に画像を埋め込む
emailString.AppendLine()
emailString.AppendLine()
emailString.AppendLine("<br />")
emailString.AppendLine("<br />")
emailString.AppendLine("<img src =""cid:C:\Users\Public\Pictures\Sample Pictures\br1.gif"" alt='STUPID IMAGE'>")
次いでlinkedresource
Sub SendEmail(ByVal errorMessage As String)
Dim mail As New MailMessage()
mail.From = New MailAddress("[email protected]", "**DAILY STATS**")
mail.Subject = "STATS ALERT"
mail.To.Add("[email protected]")
mail.IsBodyHtml = True
'mail.Body = "TEST EMAIL" 'errorMessage
'mail.BodyEncoding = Encoding.UTF8
smptpServer.Timeout = 30000
smptpServer.Credentials = New NetworkCredential("me", "person")
Dim imageBody As String = " <img src =""cid:C:\Users\Public\Pictures\Sample Pictures\br1.gif"">"
Dim htmlView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(errorMessage, Nothing, "text/html")
Dim plainTextView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(errorMessage, Nothing, "text/plain")
Dim imageResource As New System.Net.Mail.LinkedResource("C:\Users\Public\Pictures\Sample Pictures\br1.gif", MediaTypeNames.Image.Gif)
Dim attachment As System.Net.Mail.Attachment
attachment = New System.Net.Mail.Attachment("C:\Users\Public\Pictures\Sample Pictures\br1.gif")
mail.Attachments.Add(attachment)
'imageResource.ContentId = "HDIImage"
htmlView.LinkedResources.Add(imageResource)
htmlView.TransferEncoding = Net.Mime.TransferEncoding.Base64
htmlView.ContentType = New System.Net.Mime.ContentType("text/html")
'mail.AlternateViews.Add(plainTextView)
mail.AlternateViews.Add(htmlView)
Try
smptpServer.Send(mail)
Catch ex As Exception
If ex.Message.Contains("Timeout") Then
Exit Sub
End If
End Try
と異なる方法を試した私もGIFにPNGを画像の種類を変更しました。通常の手動で作成されたhtmlテーブルは、文字列に追加するときに機能しますが、上記の方法ではうまくいきません。
はこれだけが表示されます:なし: "imagename.png CID"、を
お返事ありがとうございます。はい、私は添付ファイルとして、そして身体の両方にしようとしています。画像がプロジェクトディレクトリ内にある場合にのみロードされると言っていますか? – vbNewbie
これは実際に私のために働いた。 contentidを持つ添付ファイルへの参照を追加するにはhttp://stackoverflow.com/questions/1212838/c-sharp-sending-mails-with-images-inline-using-smtpclient – vbNewbie
@vbNewbie、これは役に立ちますか? https://tools.ietf.org/html/rfc2111 – VBobCat