System.Net.Mail in .NET 2.0

G

Guest

Hi!

Inline attachments (images) doesn't seem to work. I have a html-document
that I know works fine. This works fine in another mailing-product for me.
Not sure if to use attachment with dispositiontype inline or like in these
snippet, alternativeview and linkedresource? Can anyone see whats wrong?

Here are a snippet from my html-page:

body { background-image: url(cid:back.gif); background-repeat: repeat-y;
background-attachment: fixed}

Here are a snippet from my mailing-code:

Dim l_Message As New MailMessage()
l_Message.Subject = l_strSubject
l_Message.From = New MailAddress(m_strFrom)

Dim l_RecipientsTo As MailAddressCollection = l_Message.To
Dim l_RecipientsCc As MailAddressCollection = l_Message.CC

If m_strSendTo.Length > 0 Then
For Each l_strAddressToItem As String In
m_strSendTo.TrimEnd().Split(";".ToCharArray())
l_RecipientsTo.Add(New
MailAddress(l_strAddressToItem))
Next
End If

If m_strCcTo.Length > 0 Then
For Each l_strAddressCcItem As String In
m_strCcTo.TrimEnd().Split(";".ToCharArray())
l_RecipientsCc.Add(New
MailAddress(l_strAddressCcItem))
Next
End If

l_Message.IsBodyHtml = True
l_Message.Priority = MailPriority.High

Dim avhtml As AlternateView =
AlternateView.CreateAlternateViewFromString(l_strHTMLBodyText)
avhtml.ContentType.MediaType = "text/html"
avhtml.TransferEncoding =
System.Net.Mime.TransferEncoding.QuotedPrintable
avhtml.ContentType.MediaType = "text/html"

Dim lr As LinkedResource = New
LinkedResource(m_strSMTPAttachment) 'ms, "image/gif")
lr.ContentType.MediaType =
System.Net.Mime.MediaTypeNames.Image.Gif
lr.TransferEncoding = Net.Mime.TransferEncoding.Base64
lr.ContentId = "back.gif"
lr.ContentType.Name = "back.gif"
lr.ContentLink = New Uri("cid:back.gif")
avhtml.LinkedResources.Add(lr)
l_Message.AlternateViews.Add(avhtml)

If l_strPlainTextBody.Length > 0 Then
Dim avtext As AlternateView =
AlternateView.CreateAlternateViewFromString(l_strPlainTextBody)
avtext.ContentType = New ContentType("text/plain")
avtext.ContentType.MediaType = "text/plain"
avtext.TransferEncoding = TransferEncoding.QuotedPrintable
l_Message.AlternateViews.Add(avtext)
End If

m_MailClient = New SmtpClient(m_strSMTPHost,
m_intSMTPHostPort)

m_MailClient.Credentials =
System.Net.CredentialCache.DefaultCredentials
m_MailClient.EnableSsl = False
m_MailClient.Timeout = 100000
m_MailClient.DeliveryMethod = SmtpDeliveryMethod.Network

m_MailClient.Send(l_Message)
 
G

Guest

It seems that the LinkedResource need a <img src=cid:back.gif> to work. In my
case I had an embedded cascading style sheet with a "background-image:
url(cid:back.gif);"-property. This doesn't work.

After doing some tests with Outllook 2002 and Outllook 2003 as email-client.
I found that the "background-image: url(cid:back.gif);"-syntax works fine
when opening the mail in Outlook 2002, but not in Outlook 2003.

After digging a little bit more I found out that statement
"background-image: url(cid:back.gif);" doesn't work due to security
restrictions in Outlook 2003. By disabling via Tools\Options\Security and
"Change Automatic Download Settings" all works fine. Strange though, that the
<img src=cid:back.gif> is slipping through, but the background-image:
url(cid:back.gif); doesn't !?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top