Sending mail using CDO and Outlook Exchange via a profile

rmawarner used Ask the Experts™
I have created a profile to send an email using CDO 1.21 and MS Outlook Exchange.

The code works fine to send the email from the created profile.

However, it doesn't always work! Every so often, it fails and a mail is returned from the system administrator saying 'undeliverable', 'The originator does not have permission to submit message'.

This is the code I am using:

Dim oSession       As MAPI.Session
Dim MsgNew         As MAPI.Message
Dim Recip          As MAPI.Recipient
On Error GoTo Err_Handler
'Create session.
Set oSession = CreateObject("mapi.session")
oSession.Logon "My Mail Profile", , False, True, 0, False
' Create new message.
Set MsgNew = oSession.Outbox.Messages.Add
' Set message sender.
Set MsgNew.Sender = oSession.CurrentUser
' Set message recipient.
Set Recip = MsgNew.Recipients.Add("", ,  CdoTo)
' Set other message properties and send.
With MsgNew
  .Text = MessageText
End With
Set MsgNew = Nothing
Set Recip = Nothing
Set oSession = Nothing

Any help would be greatly appreciated.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Try it using CDO:

Set oMsg = CreateObject("CDO.Message")
oMsg.To = ""
oMsg.From = ""
oMsg.Subject = "Something"

Set oMsg = Nothing


Thanks. I tried that and got the error number
-2147220960 and error desription 'The "SendUsing" configuration value is invalid.'
Any ideas?
From your code if the variable "MessageText" is ever blank I know this can cause an error it should always have a value even if its just a " " , but don't know if that will solve your problem.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!


Thanks for your suggestion Chris, but in my case the variable 'message text' is never blank.
This is an Exchange Server issue. Does this help:;en-us;q197721


'The "SendUsing" configuration value is invalid.':
This problem is discussed in:

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial