通过 MS Access VBA/Outlook 发送电子邮件,选择发送配置文件 [英] Sending email through MS Access VBA / Outlook, choosing sending profile
问题描述
我正在查看来自另一个问题的这段代码(MS Access VBA):https://stackoverflow.com/a/17975507/1085885
I am looking at this snippet of code from another question here (MS Access VBA): https://stackoverflow.com/a/17975507/1085885
现在,此代码仅在 Outlook 打开时运行它时才有效.有没有办法让这段代码打开Outlook"然后运行所有的发送代码?
Right now this code only works when I run it while Outlook is open. Is there any way for this code to "open Outlook" and then run all the sending code?
其次,我如何选择要从哪个 Outlook 配置文件发送?我可以访问几个不同的个人资料,它是从我的主要收件箱发送的,但我希望它来自我的第二个收件箱.
Secondly, how can I choose which Outlook profile to send from? I have access to a couple different profiles and it's sending from my main top inbox but I want it to come from my second inbox.
推荐答案
您需要登录到指定的配置文件.创建 Outlook 应用程序实例后
You need to log to the specified profile. After creating an instance of the Outlook application
Set oApp = CreateObject("Outlook.application")
添加如下内容:
set oNS = oApp.GetNamespace.Logon
oNS.Logon("MyProfileName")
请注意,如果 Outlook 已在运行,则登录将不执行任何操作.您将需要使用扩展 MAPI(C++ 或 Delphi 或 MAPI 包装器,如 Redemption(RDOSession.Logon) 登录到指定的配置文件.
Note if Outlook is already running, Logon will do nothing. You will need to use Extended MAPI (C++ or Delphi or a MAPI wrapper like Redemption (RDOSession.Logon) to log to a specified profile.
为什么不使用单个配置文件并创建多个帐户?然后,您可以设置 MailItem.SendUsaingAccount
属性以指定特定帐户.
Why not work with a single profile and create multiple accpunts? You can then set the MailItem.SendUsaingAccount
property to specify a particular account.
这篇关于通过 MS Access VBA/Outlook 发送电子邮件,选择发送配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!