473,795 Members | 3,175 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Net.Mail in .NET 2.0

pon
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.gi f); background-repeat: repeat-y;
background-attachment: fixed}

Here are a snippet from my mailing-code:

Dim l_Message As New MailMessage()
l_Message.Subje ct = l_strSubject
l_Message.From = New MailAddress(m_s trFrom)

Dim l_RecipientsTo As MailAddressColl ection = l_Message.To
Dim l_RecipientsCc As MailAddressColl ection = l_Message.CC

If m_strSendTo.Len gth > 0 Then
For Each l_strAddressToI tem As String In
m_strSendTo.Tri mEnd().Split("; ".ToCharArray() )
l_RecipientsTo. Add(New
MailAddress(l_s trAddressToItem ))
Next
End If

If m_strCcTo.Lengt h > 0 Then
For Each l_strAddressCcI tem As String In
m_strCcTo.TrimE nd().Split(";". ToCharArray())
l_RecipientsCc. Add(New
MailAddress(l_s trAddressCcItem ))
Next
End If

l_Message.IsBod yHtml = True
l_Message.Prior ity = MailPriority.Hi gh

Dim avhtml As AlternateView =
AlternateView.C reateAlternateV iewFromString(l _strHTMLBodyTex t)
avhtml.ContentT ype.MediaType = "text/html"
avhtml.Transfer Encoding =
System.Net.Mime .TransferEncodi ng.QuotedPrinta ble
avhtml.ContentT ype.MediaType = "text/html"

Dim lr As LinkedResource = New
LinkedResource( m_strSMTPAttach ment) 'ms, "image/gif")
lr.ContentType. MediaType =
System.Net.Mime .MediaTypeNames .Image.Gif
lr.TransferEnco ding = Net.Mime.Transf erEncoding.Base 64
lr.ContentId = "back.gif"
lr.ContentType. Name = "back.gif"
lr.ContentLink = New Uri("cid:back.g if")
avhtml.LinkedRe sources.Add(lr)
l_Message.Alter nateViews.Add(a vhtml)

If l_strPlainTextB ody.Length > 0 Then
Dim avtext As AlternateView =
AlternateView.C reateAlternateV iewFromString(l _strPlainTextBo dy)
avtext.ContentT ype = New ContentType("te xt/plain")
avtext.ContentT ype.MediaType = "text/plain"
avtext.Transfer Encoding = TransferEncodin g.QuotedPrintab le
l_Message.Alter nateViews.Add(a vtext)
End If

m_MailClient = New SmtpClient(m_st rSMTPHost,
m_intSMTPHostPo rt)

m_MailClient.Cr edentials =
System.Net.Cred entialCache.Def aultCredentials
m_MailClient.En ableSsl = False
m_MailClient.Ti meout = 100000
m_MailClient.De liveryMethod = SmtpDeliveryMet hod.Network

m_MailClient.Se nd(l_Message)
Jun 29 '06 #1
1 8627
pon
It seems that the LinkedResource need a <img src=cid:back.gi fto work. In my
case I had an embedded cascading style sheet with a "background-image:
url(cid:back.gi f);"-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.gi f);"-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.gi f);" doesn't work due to security
restrictions in Outlook 2003. By disabling via Tools\Options\S ecurity and
"Change Automatic Download Settings" all works fine. Strange though, that the
<img src=cid:back.gi fis slipping through, but the background-image:
url(cid:back.gi f); doesn't !?
"pon" wrote:
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.gi f); background-repeat: repeat-y;
background-attachment: fixed}

Here are a snippet from my mailing-code:

Dim l_Message As New MailMessage()
l_Message.Subje ct = l_strSubject
l_Message.From = New MailAddress(m_s trFrom)

Dim l_RecipientsTo As MailAddressColl ection = l_Message.To
Dim l_RecipientsCc As MailAddressColl ection = l_Message.CC

If m_strSendTo.Len gth 0 Then
For Each l_strAddressToI tem As String In
m_strSendTo.Tri mEnd().Split("; ".ToCharArray() )
l_RecipientsTo. Add(New
MailAddress(l_s trAddressToItem ))
Next
End If

If m_strCcTo.Lengt h 0 Then
For Each l_strAddressCcI tem As String In
m_strCcTo.TrimE nd().Split(";". ToCharArray())
l_RecipientsCc. Add(New
MailAddress(l_s trAddressCcItem ))
Next
End If

l_Message.IsBod yHtml = True
l_Message.Prior ity = MailPriority.Hi gh

Dim avhtml As AlternateView =
AlternateView.C reateAlternateV iewFromString(l _strHTMLBodyTex t)
avhtml.ContentT ype.MediaType = "text/html"
avhtml.Transfer Encoding =
System.Net.Mime .TransferEncodi ng.QuotedPrinta ble
avhtml.ContentT ype.MediaType = "text/html"

Dim lr As LinkedResource = New
LinkedResource( m_strSMTPAttach ment) 'ms, "image/gif")
lr.ContentType. MediaType =
System.Net.Mime .MediaTypeNames .Image.Gif
lr.TransferEnco ding = Net.Mime.Transf erEncoding.Base 64
lr.ContentId = "back.gif"
lr.ContentType. Name = "back.gif"
lr.ContentLink = New Uri("cid:back.g if")
avhtml.LinkedRe sources.Add(lr)
l_Message.Alter nateViews.Add(a vhtml)

If l_strPlainTextB ody.Length 0 Then
Dim avtext As AlternateView =
AlternateView.C reateAlternateV iewFromString(l _strPlainTextBo dy)
avtext.ContentT ype = New ContentType("te xt/plain")
avtext.ContentT ype.MediaType = "text/plain"
avtext.Transfer Encoding = TransferEncodin g.QuotedPrintab le
l_Message.Alter nateViews.Add(a vtext)
End If

m_MailClient = New SmtpClient(m_st rSMTPHost,
m_intSMTPHostPo rt)

m_MailClient.Cr edentials =
System.Net.Cred entialCache.Def aultCredentials
m_MailClient.En ableSsl = False
m_MailClient.Ti meout = 100000
m_MailClient.De liveryMethod = SmtpDeliveryMet hod.Network

m_MailClient.Se nd(l_Message)

Jul 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8675
by: Trond A. S. Andersen | last post by:
Hi, all! I'm trying to use the System.Web.Mail. "package" combinded with System.Web.Mail.SmtpMail in order to send MS Excel spreadsheets attached to mail messages. However, sending one single spreadsheet attachment per message, seems to be causing som kind of corruption of the attachment, while several spreadsheets per works just fine. Consider the following three snippets of C# code:
3
3273
by: Phil Mc | last post by:
Hi has anyone come accross the problem.... with referance to System.Web.Mail.MailMessage and System.Web.Mail.SmtpMail THIS WORKS FINE mail=new MailMessage(); mail.From = "W-MyPcName.mycompany.com"; mail.To=strTo; mail.Cc=strCC; mail.Bcc=strBCC;
5
2237
by: martin | last post by:
Hi, I have created a class that is totally seperate from my web application. However this class is used extensivly by the web application for stuff like data access. I wish to add a function to this class that will send email, however my class will not seem to recognise the system.web.mail.mailmessage. my first impression on this is that I may have to use some sort of third
3
4357
by: pmud | last post by:
Hi, I have ab ASP.Net Application in which I need to send e-mail on button click. Even though my C# code for that is correct.I am getting the following error:: I think the following error can be bcoz of the SMTP virtual server. I cant view the SMTP virtual server in IIS. How to correct this error??? Send failure: System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException:...
1
8186
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to the members of my organization. I think my problem is incorrectly setting the settings on my server or an authentication problem. Here is the code I have written to send a test message: -----Code Begins: Sensitive Information Replaced by -----...
2
3501
by: Ryan | last post by:
Hi, I receive an access denied error (see below) when attempting to send an email with BodyFormat=MailFormat.Html from an asp.net page. Exactly the same code works fine in a console application, and also succeeds from the asp.net page with BodyFormat=MailFormat.Text. I've recently upgraded from W2K SP4 to WinXP SP2 and am using .Net Framework v1.1 SP1. The code worked fine under W2K SP4.
1
5909
by: theWizard1 | last post by:
The following sends my email, but the attachment is empty. The attachment should contain the data that is in the string that was created from the xmlReader. I have a stored procedure written using For XML explicit, and it returns an xml reader. Then the following: xmlRdr.MoveToContent(); string myTemp = xmlRdr.ReadOuterXml();
2
17490
by: clevrmnkey | last post by:
I've had nothing but trouble from the System.Net.Mail objects, but I finally need to make them work, and I can't for the life of me see what I'm doing wrong. I pared back my mail transaction to the bare minimum: System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("<my mail server IP>", 25); smtp.Send("<one of my email addresses>", "<another of my email addresses>", "Hello", "World");
10
3965
by: Frank | last post by:
Hi, I am hoping to find out the differences between the System.Net.Mail and System.Web.Mail. Can some nice folks post the differences; or some urls which show the differences? Great Thanks Frank
2
6828
by: satnamsarai | last post by:
Using System.Net.Mail: Sometimes I get error 'failure sending mail. Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.' Not sure how to fix this error. I am able to send messages sometimes both other times randomly following error appear EXCEPTION:
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.