Sending Outlook message programmatically

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am building automated email messaging, populating the Subject, message and
recipients from within my application. I need to popultat the From: also,
does anyone know how to code this?
 
An Exchange mailbox? In that case, assign the mailbox alias or SMTP address to the MailItem.SentOnBehalfOfName property.
 
Here's some sample code I use in Excel to send emails using Outlook.


Dim Outlook As Outlook.Application
Dim OutlookMsg As Outlook.MailItem
Dim OutlookRecip As Outlook.Recipient
Dim OutlookAttach As Outlook.Attachment

Set Outlook = CreateObject("outlook.application")
Set OutlookMsg = Outlook.CreateItem(olMailItem)

With OutlookMsg
.SentOnBehalfOfName = "(e-mail address removed)"
.ReplyRecipients.Add
("(e-mail address removed)")
.Subject = "Read me!"
.Importance = olImportanceHigh
.Sensitivity = olConfidential
.BodyFormat = olFormatHTML
.HTMLBody = "Your message here"

Set OutlookRecip = .Recipients.Add("(e-mail address removed)")
OutlookRecip.Type = olTo

Set OutlookAttach = .Attachments.Add("C:\Documents And
Settings\username\Desktop\filename.xls")
.Send ' or .Display if you want to preview the message

'destroy variables
Set OutlookRecip = Nothing
Set OutlookAttach = Nothing
Set OutlookMsg = Nothing
Set Outlook = Nothing


Beware Outlook security warning!



HTH,
JP
 
Back
Top