• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3967
  • Last Modified:

Send Email via VB.Net, using an Outlook Template? (.Msg)

Hi,

I'm looking to send an email template with some variables filled from VB.Net via Outlook.

I was originally going to send an html email in outlook, however the email I am going to send must contain a company logo. Therefore I have a template (.msg file) that I want to send containing the text from 3 text boxes on my form.

The text boxes are:

RequestNo
Site
Message

Can anyone show me how to send my template and have these variables filled in on the form?

Thanks,

Paul.
0
m0tSiE
Asked:
m0tSiE
  • 4
  • 3
1 Solution
 
TechTiger007Commented:
For using outlook to sent mail you can refer this
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23807698.html

Not sure if you can use a template from outlook
0
 
m0tSiEAuthor Commented:
Thanks Tiger, that's the previous question I asked, unfortunetly i'm going to have to show an image on the template.

Is it possible to attach an image and display it using html?
0
 
TechTiger007Commented:
Oops sorry about that Didnt see that it was you again :-)

If the image is hosted in a web site then you can use an img tag in your mail body and give href as the URL of the image

If you need to attach the image in mail body...... Did some googling for you and here it is
http://dotnetdud.blogspot.com/2008/05/create-html-message-with-embedded.html

Hope that is what you are looking for
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
m0tSiEAuthor Commented:
Thanks Tiger, i've put together the following code but i'm still having problems.

At the minute, the email shows a broken image, which has the url cid:Img1.
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        OutApp = CreateObject("Outlook.Application")
        OutApp.Session.Logon()
        OutMail = OutApp.CreateItem(0)
 
        Dim img1 As Net.Mail.LinkedResource = New Net.Mail.LinkedResource("c:\temp\candice2.jpg", Net.Mime.MediaTypeNames.Image.Jpeg)
 
        img1.ContentId = "Img1"
 
        strbody = "<html><body><font color='red'>TEXT</font></b><br><br><img src='cid:" + img1.ContentId + "'></body></html>" & _
                  "Dear all," & vbNewLine & vbNewLine & _
                  "This is a test email." & vbNewLine & _
                  "" & vbNewLine & _
                  "" & vbNewLine & _
                  "Thanks and regards," & _
                  "" & vbNewLine & _
                  "Paul"
    End Sub

Open in new window

0
 
TechTiger007Commented:
Seems like you havent created AlternativeView for HTML body of your message. Try this I have not tested

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        OutApp = CreateObject("Outlook.Application")
        OutApp.Session.Logon()
        OutMail = OutApp.CreateItem(0)
 
Dim avHTMLBody As AlternateView

        Dim img1 As Net.Mail.LinkedResource = New Net.Mail.LinkedResource("c:\temp\candice2.jpg", Net.Mime.MediaTypeNames.Image.Jpeg)
 
        img1.ContentId = "Img1"
 
        strbody = "<html><body><font color='red'>TEXT</font></b><br><br><img src='cid:" + img1.ContentId + "'></body></html>" & _
                  "Dear all," & vbNewLine & vbNewLine & _
                  "This is a test email." & vbNewLine & _
                  "" & vbNewLine & _
                  "" & vbNewLine & _
                  "Thanks and regards," & _
                  "" & vbNewLine & _
                  "Paul"

avHTMLBody = AlternateView.CreateAlternateViewFromString(strbody, Nothing, MediaTypeNames.Text.Html)

avHTMLBody.LinkedResources.Add(img1)

oMailMsg.AlternateViews.Add(avHTMLBody)
    End Sub
0
 
TechTiger007Commented:
Do post me if you are facing any pblm with this code
0
 
m0tSiEAuthor Commented:
Cheers, worked great! :D
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now