[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Use HTML to format a System.Net.Mail email

Posted on 2009-05-01
2
Medium Priority
?
979 Views
Last Modified: 2013-12-25
Hello everyone,

I want to insert a banner link into a System.Net.Mail email message.

The image is located on a webserver so what I wanted to do was use the tag...

<img border="0" src="www.somewebsite.com/somebannerimg.png">

But when the mail gets sent via the .Net framework, the image isnt in the message, only the link

(And yes I set the body = html, although the body only contains the link above and the rest is text without any other html formatting)

We have constructed a program that periodically posts mail to users, but we want to make the messages look alot nicer than just straight plain text.
0
Comment
Question by:recruitit
2 Comments
 
LVL 16

Assisted Solution

by:hankknight
hankknight earned 400 total points
ID: 24277668
Images are only supported with recent versions of System.Net.Mail and you can't just insert the HTML code.

Here are the details:
http://www.systemnetmail.com/faq/4.4.aspx

***QUOTED TEXT*** ( http://www.systemnetmail.com/faq/4.4.aspx )
 
Embedding images is something that is new with System.Net.Mail. To embed an image you will need to
 
1. Create a LinkedResource object. The LinkedResource will actually contain the binary data of the Image. This binary data is encoded as part of the email, and sent along as part of the MailMessage. 
 
2. Give the LinkedResource a unique name, also known as a Content-Id. 
 
3. Create a HTML AlternateView. 
 
4. Inside that HTML text, you need to use the standard <img> tag. 
 
5. For the "src" value, you need to point it at the Content-Id of the LinkedResource image. This is done by using the syntax <img src="cid:whatever"> The "src=cid:" part is required for the email client to recognize the <img> tag as an embedded image, while the "whatever" part is the actual Content-Id of the LinkedResource image.  This will instruct the mail client to find an embedded image named "whatever" and display the contents *without* making a http:// request. 

Open in new window

0
 

Accepted Solution

by:
recruitit earned 0 total points
ID: 24277724
I just answered my own question.  Its very simple, you just need to format the whole thing as a web page.  If you insert this text into the System.Net.Mail.MailMessage Body and set it to html then it works perfectly, you can format the entire thing to look just like a web page.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
      <head>
            <title></title>
      </head>

<body>
<img src="someimagelink" width="980" height="70" border="1" alt="" title="" />
 </a></td>
</body>
</html>
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question