Send an Email with Outlook using VB .Net

M

Michele

Hi,
I need to send the same Email to different people. I'm using Outlook
XP and VB.Net. I tryed with the following code:

Dim oOutL As Outlook.Application
Dim oMail As Outlook._MailItem

oOutL = CreateObject("outlook.application")

For i = 0 To Email.Length - 1
oMail =
oOutL.CreateItem(Outlook.OlItemType.olMailItem)
oMail.UnRead = True
oMail.To = Email(i)
oMail.Subject = "My Subject"
oMail.HTMLBody = True
oMail.Body = "My Body"
oMail.Attachments.Add(FilePath & "attachement.html")
oMail.Send()
Next

but all i got is an Email without my name on it in the "FROM" field,
how can i add it?

another solution that I thought for send those Emails is to manually
create the Email and save it in the local disk and with VB.NET just
open it, paste the mail address in the "TO" field and send it, but I
don't know how open an Email from the code.

Can you help me?

Thanks

Michele
 
J

Jay B. Harlow [MVP - Outlook]

Michele,
In addition to OHM's suggestion of using the System.Web.Mail namespace,
which for simply sending emails is much easier.

Do you have the XP PIA installed? See "Office XP Primary Interop Assembly"
at the url below.

The following code works with Outlook 2003 with the Outlook 2003 PIA
installed, of course it is subject to the Outlook security prompts.

Dim oOutL As New Outlook.Application
Dim oMail As Outlook.MailItem

oMail = oOutL.CreateItem(Outlook.OlItemType.olMailItem)
oMail.UnRead = True
oMail.To = "(e-mail address removed)"
oMail.Subject = "My Subject"
oMail.HTMLBody = True
oMail.Body = "My Body"
oMail.Attachments.Add("attachement.html")
oMail.Send()
Return

The following site contains a plethora of articles on using Outlook with
..NET:

http://www.microeye.com/resources/res_outlookvsnet.htm

To avoid the Outlook security prompts its generally easiest to create a
properly constructed COM-Addin for Outlook 2003. There are other methods
available for other versions of Outlook...

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top