I know zip about vb but am attempting to automate an email using outlook. I have pulled several examples of code, and found 1 that works, except I cant seem to get it to accept a variable in the message body:
let>var1="sample variable"
VBSTART
Sub SendOutlookMail
Set objOutlook = CreateObject("Outlook.Application")
Set objMailItem = objOutlook.CreateItem(0)
' // Option Values for Outlook Object CreateItem( ) are:
' // 0=MailItem, 1=AppointmentItem, 2=ContactItem, 3=TaskItem
' // 4=JournalItem, 5=NoteItem, 6=PostItem
objMailItem.To = "[email protected]" ' This is the primary recipient
objMailItem.Subject = "test" ' This is the Subject
objMailItem.Body = ("%var1%") ' This is the Email message
Set objMailer = objOutlook.GetNameSpace("MAPI")
objMailer.Logon "Outlook", "Actual Password" 'Logon to Mailer
objMailItem.Send ' send method
' // Use Save method vs. Send to put email in Drafts Folder vs. Outbox/Sending
' // objMailItem.Save ' save method
objMailer.Logoff ' Logoff from Mailer
End Sub
'=======================================
VBEND
VBRun>SendOutlookMail
please help, thank you.
passing variable to vbscript for outlook
Moderators: JRL, Dorian (MJT support)
I think you need to pass the variable in the sub call (see x in VB part and extra parameter in VBRun call).
VBSTART
Sub SendOutlookMail(x)
Set objOutlook = CreateObject("Outlook.Application")
Set objMailItem = objOutlook.CreateItem(0)
' // Option Values for Outlook Object CreateItem( ) are:
' // 0=MailItem, 1=AppointmentItem, 2=ContactItem, 3=TaskItem
' // 4=JournalItem, 5=NoteItem, 6=PostItem
objMailItem.To = "[email protected]" ' This is the primary recipient
objMailItem.Subject = "test" ' This is the Subject
objMailItem.Body = x ' This is the Email message
Set objMailer = objOutlook.GetNameSpace("MAPI")
objMailer.Logon "Outlook", "Actual Password" 'Logon to Mailer
objMailItem.Send ' send method
' // Use Save method vs. Send to put email in Drafts Folder vs. Outbox/Sending
' // objMailItem.Save ' save method
objMailer.Logoff ' Logoff from Mailer
End Sub
'=======================================
VBEND
let>var1="sample variable"
VBRun>SendOutlookMail,%var1%
VBSTART
Sub SendOutlookMail(x)
Set objOutlook = CreateObject("Outlook.Application")
Set objMailItem = objOutlook.CreateItem(0)
' // Option Values for Outlook Object CreateItem( ) are:
' // 0=MailItem, 1=AppointmentItem, 2=ContactItem, 3=TaskItem
' // 4=JournalItem, 5=NoteItem, 6=PostItem
objMailItem.To = "[email protected]" ' This is the primary recipient
objMailItem.Subject = "test" ' This is the Subject
objMailItem.Body = x ' This is the Email message
Set objMailer = objOutlook.GetNameSpace("MAPI")
objMailer.Logon "Outlook", "Actual Password" 'Logon to Mailer
objMailItem.Send ' send method
' // Use Save method vs. Send to put email in Drafts Folder vs. Outbox/Sending
' // objMailItem.Save ' save method
objMailer.Logoff ' Logoff from Mailer
End Sub
'=======================================
VBEND
let>var1="sample variable"
VBRun>SendOutlookMail,%var1%
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Here's a simple example:
Change the last part of hagchr's example to:
Let>var1=sample variable
VBRun>SendOutlookMail,var1
Code: Select all
VBSTART
Sub MySub(msg)
MsgBox msg
End Sub
VBEND
Let>local_var=Hello World
VBRun>MySub,local_var
Let>var1=sample variable
VBRun>SendOutlookMail,var1
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?