Trying to send Outlook email via VB Script - undeliverable errors

Not open for further replies.


I have a program that I need to send an alert to my email from when a certain event happens. I found a VBScript on MS Technet that should work.



' NAME: MailUsingOutlook.vbs


' COMMENT: This script generates an e-mail using the Outlook client.



'Create an Outlook object

Dim Outlook 'As New Outlook.Application

Set Outlook = CreateObject(" Outlook.Application" )

'Create e new message

Dim Message 'As Outlook.MailItem

Set Message = Outlook.CreateItem(olMailItem)

With Message
.Subject = " New event"
.Body = " New event"
'Set destination email address
.Recipients.Add (" john smith" )
'Set sender address.
Const olOriginator = 0
.Recipients.Add(" john smith" ).Type = olOriginator
'Send the Message

End With

However when I run the VBScript, i get the following undeliverable email message in Outlook 2007.

Your message did not reach some or all of the intended recipients.
Subject: New event
Sent: 7/28/2010 12:10 PM

The following recipient(s) cannot be reached:
SMITH, JOHN on 7/28/2010 12:10 PM
This message could not be sent. Try sending the message again later, or contact your network administrator. Error is [0x80070057-00000000-00000000].

I am running Windows 7 Enterprise, Outlook 2007 in Cached Exchange Mode.

Sue Mosher - Outlook MVP

I see two potential problems. First, the approach you're using to set the sender doesn't work. Use the MailItem.SentOnBehalfOfName property instead. Second, do not send the message unless all recipients resolve, i.e. Recipients.ResolveAll returns True. Instead, you will need to display the message so the user can resolve the unresolved recipient.

Also, what mechanism are you using to invoke this script?


Thanks for the reply. I originally got the VBScript MailUsingOutlook.vbs from the Script Repository at MS TechNet so I believed that it should work, but I guess not.

Can you give me some more info on the MailItem.SentOnBehalfOfName and how it is used in a VBScript??

I am trying to get an alert program to run the VBScript to send me an email when I recieve an alert/ticket for our help desk system.

Sue Mosher - Outlook MVP

It works just like any other string property:
Message.SentOnBehalfOfName = ""

For best results, use the email address for both that property and adding recipients, not the display name.

How does this " alert program" know when to the script? Have you thought about using Outlook VBA for this?
Not open for further replies.
Thread starter Similar threads Forum Replies Date
O outlook 2010 - trying to send JPG attachments, but they are automatically converted into DAT files a Using Outlook 2
A Outlook 2007 periodically (1-2 times per day)locks up when trying to send email. I digitally sign all mail. When Outlook became non-responsive Using Outlook 2
C Error code 0x8004210a when trying to send/receive mails in Outlook 2003 Using Outlook 2
D I am able to send emails on Outlook, but unable to retrieve emails trying to come in. Using Outlook 1
J error 0X800ccc90 when trying to send or receive mails in Outlook Using Outlook 1
C How do I disable Outlook warning dialogue box "A Program is trying to send an e-mail message on your Using Outlook 2
C My Outlook is trying to send a 'ghost' e-mail...ones that have been deleted from the sent items list or outgoing e-mails list. Using Outlook 2
S Encounter "operation Failed" when trying to send email in outlook 2007. Using Outlook 4
D getting error 0X80040600 when trying to send and receive emails in Outlook 2007 Using Outlook 4
B OUTLOOK my send/recieve is trying to load over 1000 emails Y Using Outlook 1
T I am trying to use Outlook 2000 for my e mails I can receive emails but not send I keep getting error massage unable to find WAB DLL for Windows Conta Using Outlook 1
M Trying to send 68MB file to a printers - send/rec says complete but email still in outbox and says cannot open as outlook has begun transmitting the m Using Outlook 4
G trying to send emails - using Outlook 2002 - how do I upgrade Using Outlook 1
T program stuck in send mode, will not stop trying to send. now can't even get outlook to come up. Using Outlook 3
R I am getting the Outlook error message 0x8DE00006 when trying to send. Using Outlook 1
M unkonwn error 0x80040154 when trying to send/rec in outlook 2010. Using Outlook 2
A Outlook Crashes when trying to send me mails Using Outlook 1
K A program is trying to send an e-mail message on your behalf... Using Outlook 1
K Wont send or recieve now with new server keeps asking for password when trying Using Outlook 1
C Error message when trying to send email using a distribution list Using Outlook 2
T Error code: Error Code OX800CCC7D. Can receive email but when trying to send email it goes to the ou Using Outlook 2
L Trying to receive email without the send/receive command Using Outlook 6
J Re: Some controls are not valid, when trying to change send as permission Exchange Server Administration 0
J Problems trying to send attachemnt direct from Office program Using Outlook 5
P No emails in outbox but trying to send emails??? Using Outlook 2
D I'm trying to send & receive e-mail. Using Outlook 2
D when trying to send mail a box comes up entitled: ENTER NETWORK PASSWORD and keeps returning over & over again even if I shut computer down Using Outlook 1
A Re: Some controls are not valid, when trying to change send as permission Exchange Server Administration 0
B names not showing up in address book when trying to send mails Using Outlook 1
J Permissions problems when trying to 'manage Send As' on public folders - Exchange 2010 Exchange Server Administration 3
W error code 0x800CCC92 with emails. cant seem to send receive. have windows 7 and trying to use outlo Using Outlook 1
B Cannot use address book/contacts when trying to send mail Using Outlook 4
M email is locked up trying to send a huge file Using Outlook 1
J Some controls are not valid, when trying to change send as permission Exchange Server Administration 5
D On one of my mail accounts receiving works but when trying to send it keeps asking for name and password even though the ones it has are correct Using Outlook 1
A Run-time error '430' on certain emails when trying to set "Outlook.mailitem" as "ActiveExplorer.Selection.Item" Outlook VBA and Custom Forms 2
R Error when trying to forward current email item Outlook VBA and Custom Forms 7
X I have met my waterloo trying to resolve embedded graphics problem with outlook 2007 and now 2016 Using Outlook 1
O The page that you are trying to access cannot be loaded. Using Outlook 0
C Trying to populate an appointment ComboBox from Excel Outlook VBA and Custom Forms 2
T Outlook "A program is trying to access Outlook" Using Outlook 3
S SendFromAccount - Problem trying to test existing value in open email Outlook VBA and Custom Forms 2
N Error 0x80090326 when trying to setup IMAP account on Using accounts in Outlook 1
KURTiS MAXiMUS Trying to appactivate ERP window Outlook VBA and Custom Forms 16
R Trying to extract information between two symbols from outlook subject Using Outlook 2
Danie Lawson Trying to recover calendar Using Outlook 4
L Trying to open contacts pst. file in outlook 365 Using Outlook 3
L Trying to check for the absence of mail. Outlook VBA and Custom Forms 1
M trying to disable junk email filter. completely. Using Outlook 4
D Trying to repair Outlook rules Using Outlook 5
Similar threads