johnywhite
asked on
System.Net.Mail.MailMessage Inline Attachment
How do I add an image inline my mail message. I am using the built in MailMessage in the .net framework.
ASKER
I am not sure if this is what I was looking for. What I want is the image to be an attachment on the email, and in the body of the email have it display that image.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This shows how to insert an in line image
<img src="c:\temp\myimage.gif" width=300 height=75>
into the body of an email message
Thanks;
Fernando Soto
The above text information was typed into a multiline text box in this example was called txtBody. The "<img src=" html tage identifies the image to be placed in the body of the text. The MailMessage IsBodyHtml property must be set to True. See test code below.
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
SendEmail(txtFrom.Text.Tri
txtSubject.Text.Trim(), txtBody.Text)
End Sub
Private Sub SendEmail(ByVal sender As String, _
ByVal recipient As String, ByVal subject As String, _
ByVal body As String, Optional ByVal attachmentString As String = "")
Dim fromAddress As New MailAddress(sender)
Dim toAddress As New MailAddress(recipient)
Dim message As New MailMessage(fromAddress, toAddress)
Dim mailSender As SmtpClient
' This next line needs to be modified for your Smtp server
mailSender = New SmtpClient("smtp-server.my
message.Bcc.Add(fromAddres
message.Subject = subject
message.IsBodyHtml = True
message.Body = body
If Not attachmentString = "" Then
Dim msgAttach As New Attachment(attachmentStrin
message.Attachments.Add(ms
End If
Try
mailSender.Send(message)
Catch ex As Exception
MessageBox.Show(ex.Message
End Try
End Sub
Fernando