VBA to Send message from a named Mailbox

  • Thread starter Thread starter Robin9876
  • Start date Start date
R

Robin9876

In VBA code (from Access) what is required to create and send mail via
Outlook from a named Exchange Mailbox, where there are more than 1
Exchange Mailboxes configured in Outlook?
 
Set the SentOnBehalfOfName property of the outgoing message to the mailbox alias.
 
How would you add the Outlook reference see it works on pc's with
Outlook 2003 or 2007 installed?
 
AFAIK, each user would need to do that manually. Maybe an Access forum would have other ideas.
 
I have now found out more details to the original scenario. The
default account is an Exchange Mailbox and the other account is a non-
Exchange mailbox hosted elsewhere on the WAN. Both can be configured
in Outlook.

Would the above suggestion when sending on behalf route the message
via that mail connection or go via the default?
 
No, for that scenario, you'd need to set the actual send account. Outlook 2007 adds a MailItem.SendUsingAccount property. For earlier versions, Outlook provides no direct way to change the account for an outgoing message. These are known workarounds using native Outlook functionality:

1) If the user has Outlook 2002/3 and is not using WordMail as the editor, you set the sending account using CommandBars techniques. See http://www.outlookcode.com/codedetail.aspx?id=889 for sample code.

2) If you're mainly concerned about replies to your message going to the correct place, add the desired reply address to the MailItem.ReplyRecipients collection.

The third-party Redemption ( http://www.dimastr.com/redemption/ ) library adds another solutions:

3) Set the RDOMail.Account property, as described at http://www.dimastr.com/redemption/rdo/RDOMail.htm

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Robin9876 said:
I have now found out more details to the original scenario. The
default account is an Exchange Mailbox and the other account is a non-
Exchange mailbox hosted elsewhere on the WAN. Both can be configured
in Outlook.

Would the above suggestion when sending on behalf route the message
via that mail connection or go via the default?
On 22 Nov, 16:23, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Set the SentOnBehalfOfName property of the outgoing message to the mailbox alias.
In VBA code (from Access) what is required to create and send mail via
Outlook from a named Exchange Mailbox, where there are more than 1
Exchange Mailboxes configured in Outlook?
 
As another workaround, can the Outlook Mail Profile be selected in
code and therefore is only one account to send as.

No, for that scenario, you'd need to set the actual send account. Outlook 2007 adds a MailItem.SendUsingAccount property. For earlier versions, Outlook provides no direct way to change the account for an outgoing message. These are known workarounds using native Outlook functionality:

1) If the user has Outlook 2002/3 and is not using WordMail as the editor, you set the sending account using CommandBars techniques. Seehttp://www.outlookcode.com/codedetail.aspx?id=889for sample code.

2) If you're mainly concerned about replies to your message going to the correct place, add the desired reply address to the MailItem.ReplyRecipients collection.

The third-party Redemption (http://www.dimastr.com/redemption/) library adds another solutions:

3) Set the RDOMail.Account property, as described athttp://www.dimastr.com/redemption/rdo/RDOMail.htm

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54

Robin9876 said:
I have now found out more details to the original scenario. The
default account is an Exchange Mailbox and the other account is a non-
Exchange mailbox hosted elsewhere on the WAN. Both can be configured
in Outlook.
Would the above suggestion when sending on behalf route the message
via that mail connection or go via the default?
On 22 Nov, 16:23, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Set the SentOnBehalfOfName property of the outgoing message to the mailbox alias.
In VBA code (from Access) what is required to create and send mail via
Outlook from a named Exchange Mailbox, where there are more than 1
Exchange Mailboxes configured in Outlook?
 
Not if Outlook is already running. Only one Outlook session can be running at a time.

Is Outlook really necessary to your Access application? Have you thought about using CDO for Windows to send directly through an SMTP server?

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Robin9876 said:
As another workaround, can the Outlook Mail Profile be selected in
code and therefore is only one account to send as.

No, for that scenario, you'd need to set the actual send account. Outlook 2007 adds a MailItem.SendUsingAccount property. For earlier versions, Outlook provides no direct way to change the account for an outgoing message. These are known workarounds using native Outlook functionality:

1) If the user has Outlook 2002/3 and is not using WordMail as the editor, you set the sending account using CommandBars techniques. Seehttp://www.outlookcode.com/codedetail.aspx?id=889for sample code.

2) If you're mainly concerned about replies to your message going to the correct place, add the desired reply address to the MailItem.ReplyRecipients collection.

The third-party Redemption (http://www.dimastr.com/redemption/) library adds another solutions:

3) Set the RDOMail.Account property, as described athttp://www.dimastr.com/redemption/rdo/RDOMail.htm

Robin9876 said:
I have now found out more details to the original scenario. The
default account is an Exchange Mailbox and the other account is a non-
Exchange mailbox hosted elsewhere on the WAN. Both can be configured
in Outlook.
Would the above suggestion when sending on behalf route the message
via that mail connection or go via the default?
On 22 Nov, 16:23, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Set the SentOnBehalfOfName property of the outgoing message to the mailbox alias.
In VBA code (from Access) what is required to create and send mail via
Outlook from a named Exchange Mailbox, where there are more than 1
Exchange Mailboxes configured in Outlook?
 
It is connecting to a mail server via LMAP which I thought CDO only
connects to SMTP server?

Not if Outlook is already running. Only one Outlook session can be running at a time.

Is Outlook really necessary to your Access application? Have you thought about using CDO for Windows to send directly through an SMTP server?

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54

Robin9876 said:
As another workaround, can the Outlook Mail Profile be selected in
code and therefore is only one account to send as.
No, for that scenario, you'd need to set the actual send account. Outlook 2007 adds a MailItem.SendUsingAccount property. For earlier versions, Outlook provides no direct way to change the account for an outgoing message. These are known workarounds using native Outlook functionality:
1) If the user has Outlook 2002/3 and is not using WordMail as the editor, you set the sending account using CommandBars techniques. Seehttp://www.outlookcode.com/codedetail.aspx?id=889forsample code.
2) If you're mainly concerned about replies to your message going to the correct place, add the desired reply address to the MailItem.ReplyRecipients collection.
The third-party Redemption (http://www.dimastr.com/redemption/) library adds another solutions:
3) Set the RDOMail.Account property, as described athttp://www.dimastr.com/redemption/rdo/RDOMail.htm
I have now found out more details to the original scenario. The
default account is an Exchange Mailbox and the other account is a non-
Exchange mailbox hosted elsewhere on the WAN. Both can be configured
in Outlook.
Would the above suggestion when sending on behalf route the message
via that mail connection or go via the default?
On 22 Nov, 16:23, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Set the SentOnBehalfOfName property of the outgoing message to the mailbox alias.
In VBA code (from Access) what is required to create and send mail via
Outlook from a named Exchange Mailbox, where there are more than 1
Exchange Mailboxes configured in Outlook?
 
Do you mean IMAP, not LMAP? IMAP is a protocol for receiving messages. SMTP is the protocol used for sending.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Robin9876 said:
It is connecting to a mail server via LMAP which I thought CDO only
connects to SMTP server?

Not if Outlook is already running. Only one Outlook session can be running at a time.

Is Outlook really necessary to your Access application? Have you thought about using CDO for Windows to send directly through an SMTP server?

Robin9876 said:
As another workaround, can the Outlook Mail Profile be selected in
code and therefore is only one account to send as.
On 23 Nov, 14:18, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
No, for that scenario, you'd need to set the actual send account. Outlook 2007 adds a MailItem.SendUsingAccount property. For earlier versions, Outlook provides no direct way to change the account for an outgoing message. These are known workarounds using native Outlook functionality:
1) If the user has Outlook 2002/3 and is not using WordMail as the editor, you set the sending account using CommandBars techniques. Seehttp://www.outlookcode.com/codedetail.aspx?id=889forsample code.
2) If you're mainly concerned about replies to your message going to the correct place, add the desired reply address to the MailItem.ReplyRecipients collection.
The third-party Redemption (http://www.dimastr.com/redemption/) library adds another solutions:
3) Set the RDOMail.Account property, as described athttp://www.dimastr.com/redemption/rdo/RDOMail.htm
I have now found out more details to the original scenario. The
default account is an Exchange Mailbox and the other account is a non-
Exchange mailbox hosted elsewhere on the WAN. Both can be configured
in Outlook.
Would the above suggestion when sending on behalf route the message
via that mail connection or go via the default?
On 22 Nov, 16:23, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Set the SentOnBehalfOfName property of the outgoing message to the mailbox alias.
In VBA code (from Access) what is required to create and send mail via
Outlook from a named Exchange Mailbox, where there are more than 1
Exchange Mailboxes configured in Outlook?
 
Yes it is IMAP, so the SMTP by sending either with the toolbar or CDO
should work.

Do you mean IMAP, not LMAP? IMAP is a protocol for receiving messages. SMTP is the protocol used for sending.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54

Robin9876 said:
It is connecting to a mail server via LMAP which I thought CDO only
connects to SMTP server?
Not if Outlook is already running. Only one Outlook session can be running at a time.
Is Outlook really necessary to your Access application? Have you thought about using CDO for Windows to send directly through an SMTP server?
As another workaround, can the Outlook Mail Profile be selected in
code and therefore is only one account to send as.
On 23 Nov, 14:18, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
No, for that scenario, you'd need to set the actual send account. Outlook 2007 adds a MailItem.SendUsingAccount property. For earlier versions, Outlook provides no direct way to change the account for an outgoing message. These are known workarounds using native Outlook functionality:
1) If the user has Outlook 2002/3 and is not using WordMail as the editor, you set the sending account using CommandBars techniques. Seehttp://www.outlookcode.com/codedetail.aspx?id=889forsamplecode.
2) If you're mainly concerned about replies to your message going to the correct place, add the desired reply address to the MailItem.ReplyRecipients collection.
The third-party Redemption (http://www.dimastr.com/redemption/) library adds another solutions:
3) Set the RDOMail.Account property, as described athttp://www.dimastr.com/redemption/rdo/RDOMail.htm
I have now found out more details to the original scenario. The
default account is an Exchange Mailbox and the other account is a non-
Exchange mailbox hosted elsewhere on the WAN. Both can be configured
in Outlook.
Would the above suggestion when sending on behalf route the message
via that mail connection or go via the default?
On 22 Nov, 16:23, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Set the SentOnBehalfOfName property of the outgoing message to the mailbox alias.
In VBA code (from Access) what is required to create and send mail via
Outlook from a named Exchange Mailbox, where there are more than 1
Exchange Mailboxes configured in Outlook?
 
Do you know what happens if you already have Outlook open on the pc
and then use CDO to send a message from another VBA application?

Yes it is IMAP, so the SMTP by sending either with the toolbar or CDO
should work.

Do you mean IMAP, not LMAP? IMAP is a protocol for receiving messages. SMTP is the protocol used for sending.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
Robin9876 said:
It is connecting to a mail server via LMAP which I thought CDO only
connects to SMTP server?
On 23 Nov, 15:48, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Not if Outlook is already running. Only one Outlook session can be running at a time.
Is Outlook really necessary to your Access application? Have you thought about using CDO for Windows to send directly through an SMTP server?
As another workaround, can the Outlook Mail Profile be selected in
code and therefore is only one account to send as.
On 23 Nov, 14:18, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
No, for that scenario, you'd need to set the actual send account. Outlook 2007 adds a MailItem.SendUsingAccount property. For earlier versions, Outlook provides no direct way to change the account for an outgoing message. These are known workarounds using native Outlook functionality:
1) If the user has Outlook 2002/3 and is not using WordMail as the editor, you set the sending account using CommandBars techniques. Seehttp://www.outlookcode.com/codedetail.aspx?id=889forsamplecode.
2) If you're mainly concerned about replies to your message going to the correct place, add the desired reply address to the MailItem.ReplyRecipients collection.
The third-party Redemption (http://www.dimastr.com/redemption/) library adds another solutions:
3) Set the RDOMail.Account property, as described athttp://www.dimastr.com/redemption/rdo/RDOMail.htm
I have now found out more details to the original scenario. The
default account is an Exchange Mailbox and the other account is a non-
Exchange mailbox hosted elsewhere on the WAN. Both can be configured
in Outlook.
Would the above suggestion when sending on behalf route the message
via that mail connection or go via the default?
On 22 Nov, 16:23, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Set the SentOnBehalfOfName property of the outgoing message to the mailbox alias.
In VBA code (from Access) what is required to create and send mail via
Outlook from a named Exchange Mailbox, where there are more than 1
Exchange Mailboxes configured in Outlook?
 
Nothing in particular happens. CDO for Windows doesn't use Outlook in any way.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Robin9876 said:
Do you know what happens if you already have Outlook open on the pc
and then use CDO to send a message from another VBA application?

Yes it is IMAP, so the SMTP by sending either with the toolbar or CDO
should work.

Do you mean IMAP, not LMAP? IMAP is a protocol for receiving messages. SMTP is the protocol used for sending.
It is connecting to a mail server via LMAP which I thought CDO only
connects to SMTP server?
On 23 Nov, 15:48, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Not if Outlook is already running. Only one Outlook session can be running at a time.
Is Outlook really necessary to your Access application? Have you thought about using CDO for Windows to send directly through an SMTP server?
 
I have used the VBA example code for CDO message from the following
Microsoft KB article http://support.microsoft.com/kb/161833

However the message were queued up in in this profile until I logged
in to it in Outlook.

How is it possible in the code to force a send message for this
profile?

Nothing in particular happens. CDO for Windows doesn't use Outlook in any way.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54

Robin9876 said:
Do you know what happens if you already have Outlook open on the pc
and then use CDO to send a message from another VBA application?
Yes it is IMAP, so the SMTP by sending either with the toolbar or CDO
should work.
On 23 Nov, 18:55, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Do you mean IMAP, not LMAP? IMAP is a protocol for receiving messages. SMTP is the protocol used for sending.
It is connecting to a mail server via LMAP which I thought CDO only
connects to SMTP server?
On 23 Nov, 15:48, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Not if Outlook is already running. Only one Outlook session can be running at a time.
Is Outlook really necessary to your Access application? Have you thought about using CDO for Windows to send directly through an SMTP server?
 
That's CDO 1.21, which is completely different from the CDO for Windows library that I recommended as a way of bypassing Outlook completely. If you want to use CDO 1.21 and contend with its security prompts, you can use its Session.DeliverNow method to send whatever is in the Outbox.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Robin9876 said:
I have used the VBA example code for CDO message from the following
Microsoft KB article http://support.microsoft.com/kb/161833

However the message were queued up in in this profile until I logged
in to it in Outlook.

How is it possible in the code to force a send message for this
profile?

Nothing in particular happens. CDO for Windows doesn't use Outlook in any way.
Robin9876 said:
Do you know what happens if you already have Outlook open on the pc
and then use CDO to send a message from another VBA application?
Yes it is IMAP, so the SMTP by sending either with the toolbar or CDO
should work.
On 23 Nov, 18:55, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Do you mean IMAP, not LMAP? IMAP is a protocol for receiving messages. SMTP is the protocol used for sending.
It is connecting to a mail server via LMAP which I thought CDO only
connects to SMTP server?
On 23 Nov, 15:48, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Not if Outlook is already running. Only one Outlook session can be running at a time.
Is Outlook really necessary to your Access application? Have you thought about using CDO for Windows to send directly through an SMTP server?
 
I did not realise there was a difference.

Are you able to tell within the code that as message has been
successfully sent?

That's CDO 1.21, which is completely different from the CDO for Windows library that I recommended as a way of bypassing Outlook completely. If you want to use CDO 1.21 and contend with its security prompts, you can use its Session.DeliverNow method to send whatever is in the Outbox.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54

Robin9876 said:
I have used the VBA example code for CDO message from the following
Microsoft KB articlehttp://support.microsoft.com/kb/161833
However the message were queued up in in this profile until I logged
in to it in Outlook.
How is it possible in the code to force a send message for this
profile?
Nothing in particular happens. CDO for Windows doesn't use Outlook in any way.
Do you know what happens if you already have Outlook open on the pc
and then use CDO to send a message from another VBA application?
Yes it is IMAP, so the SMTP by sending either with the toolbar or CDO
should work.
On 23 Nov, 18:55, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Do you mean IMAP, not LMAP? IMAP is a protocol for receiving messages. SMTP is the protocol used for sending.
It is connecting to a mail server via LMAP which I thought CDO only
connects to SMTP server?
On 23 Nov, 15:48, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Not if Outlook is already running. Only one Outlook session can be running at a time.
Is Outlook really necessary to your Access application? Have you thought about using CDO for Windows to send directly through an SMTP server?
 
There is a huge difference. CDO 1.21 depends on Outlook mail profiles and will give you security prompts. CDO for Windows needs only SMTP server information and involves no security prompts; I recommend it for your scenario. It should give you some indicator of message send success or failure, but I've never looked for the details. For CDO 1.21, of course, you would know the item is successfully sent when it arrives in the Sent Items folder.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Robin9876 said:
I did not realise there was a difference.

Are you able to tell within the code that as message has been
successfully sent?

That's CDO 1.21, which is completely different from the CDO for Windows library that I recommended as a way of bypassing Outlook completely. If you want to use CDO 1.21 and contend with its security prompts, you can use its Session.DeliverNow method to send whatever is in the Outbox.

Robin9876 said:
I have used the VBA example code for CDO message from the following
Microsoft KB articlehttp://support.microsoft.com/kb/161833
However the message were queued up in in this profile until I logged
in to it in Outlook.
How is it possible in the code to force a send message for this
profile?
On 27 Nov, 17:34, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Nothing in particular happens. CDO for Windows doesn't use Outlook in any way.
Do you know what happens if you already have Outlook open on the pc
and then use CDO to send a message from another VBA application?
Yes it is IMAP, so the SMTP by sending either with the toolbar or CDO
should work.
On 23 Nov, 18:55, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Do you mean IMAP, not LMAP? IMAP is a protocol for receiving messages. SMTP is the protocol used for sending.
It is connecting to a mail server via LMAP which I thought CDO only
connects to SMTP server?
On 23 Nov, 15:48, "Sue Mosher [MVP-Outlook]" <[email protected]>
wrote:
Not if Outlook is already running. Only one Outlook session can be running at a time.
Is Outlook really necessary to your Access application? Have you thought about using CDO for Windows to send directly through an SMTP server?
 
Back
Top