【发布时间】:2018-08-14 02:55:39
【问题描述】:
在旧版 vb6 程序中,我使用以下代码使用完整版 Outlook(不是 Outlook Express)发送电子邮件。效果很好。
现在用户希望“发件人:”地址因不同用途而不同,以便在回复电子邮件时,回复将显示在 Outlook 的用户收件箱中。目前发件人是主要的企业电子邮件地址。
我认为这很容易解决;我只需要在 OutMail 对象中设置 .from 属性,但是 OutMail 对象中似乎没有“.from”属性。 (可以叫别的吗?)
所以此时我想知道它现在是如何工作的,没有指定 .from,我假设用户在 Outlook 中设置了多个电子邮件帐户,它使用的是企业的主要电子邮件,而不是个人用户。
如何使用此技术指定发件人电子邮件地址?
Dim mOutlookApp As Object
Set mOutlookApp = GetObject("", "Outlook.application")
Dim olNs As Object
Set olNs = mOutlookApp.GetNamespace("MAPI")
olNs.Logon
Dim OutMail As Object
Set OutMail = mOutlookApp.CreateItem(0)
'Set the To and Subject lines. Send the message.
With OutMail
.To = txtTo
.CC = txtCC
.Subject = txtSubjext
.HTMLBody = txtBody & vbCrLf
Dim myAttachments As Object
Set myAttachments = .Attachments
vAttach = Split(mAttachments, ",")
For i = 0 To UBound(vAttach)
myAttachments.add vAttach(i)
Next i
Dim myFolder As Object
Set myFolder = olNs.GetDefaultFolder(5) 'olFolderSent
Set .SaveSentMessageFolder = myFolder
StatusBar1.Panels(1).Text = "Status: Sending"
.send
End With
【问题讨论】:
标签: email outlook automation vb6 mapi