C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Email »

Sending mail with image Embed in HTML


Posted Date: 17 Nov 2008    Resource Type: Code Snippets    Category: Email
Author: RamyaMember Level: Silver    
Rating: 1 out of 5Points: 5



1.Add one web form
2.Place a button
3.Copy and paste the below code in button_click
4.Add a folder to soltion explorer and name it as "Images"
5.Place an image in that folder


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim msg As New MailMessage("ramya.r@shriram.com", "ramya.r@shriram.com")

msg.Subject = "This is my first email through program"
msg.IsBodyHtml = True

Dim smtpClient As New SmtpClient()
Dim View As AlternateView
Dim resource As LinkedResource
Dim msgText As New StringBuilder

msgText.Append("<p>Hi there,<p>")
msgText.Append("<p>Welcome to the new world programming.<p><br>")
msgText.Append("<p>Thanks<p>")
msgText.Append("<p>With regards,<p><br>")
msgText.Append("<img src=cid:Image1 />")

'create an alternate view for your mail
View = AlternateView.CreateAlternateViewFromString(msgText.ToString(), Nothing, "text/html")

'link the resource to embedd
resource = New LinkedResource((Server.MapPath("Sunset.jpg")))

'name the resource
resource.ContentId = "Image1"

'add the resource to the alternate view
View.LinkedResources.Add(resource)

'add the view to the message
msg.AlternateViews.Add(View)
smtpClient.Host = "< SMTP SERVER NAME >"
smtpClient.Port = 25
smtpClient.UseDefaultCredentials = True
smtpClient.Credentials = New System.Net.NetworkCredential("< USER NAME >", "< PASSWORD >")
smtpClient.Send(msg)
End Sub



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Mail  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to send email by ASP.Net C#
Previous Resource: Sending Email Using ASP.Net and C#
Return to Discussion Resource Index
Post New Resource
Category: Email


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use