Solved

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

Posted on 2008-10-12
7
3,868 Views
Last Modified: 2012-05-05
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
Comment
Question by:m0tSiE
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22697955
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
 

Author Comment

by:m0tSiE
ID: 22697971
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
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22698052
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:m0tSiE
ID: 22698495
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
 
LVL 13

Accepted Solution

by:
TechTiger007 earned 500 total points
ID: 22698539
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
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22785636
Do post me if you are facing any pblm with this code
0
 

Author Closing Comment

by:m0tSiE
ID: 31505450
Cheers, worked great! :D
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

690 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