Sending mail using CDO and Outlook Exchange via a profile

rmawarner
rmawarner used Ask the Experts™
on
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("me@my-company.com", ,  CdoTo)
Recip.Resolve
 
' Set other message properties and send.
With MsgNew
  .Text = MessageText
  .Update    
  .Send
End With
 
Set MsgNew = Nothing
Set Recip = Nothing
oSession.Logoff
Set oSession = Nothing


Any help would be greatly appreciated.
Comment
Watch Question

Do more with

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

Commented:
Try it using CDO:

Set oMsg = CreateObject("CDO.Message")
oMsg.To = "HR@xxx.de"
oMsg.From = "Engineering@xxx.de"
oMsg.Subject = "Something"
Msg.Send

Set oMsg = Nothing

Author

Commented:
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!

Author

Commented:
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:

http://support.microsoft.com/default.aspx?scid=KB;en-us;q197721

Andrew

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

http://www.slipstick.com/files/Q324037.doc

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