【问题标题】:How to set from email address when sending email by automation with outlook使用Outlook自动发送电子邮件时如何从电子邮件地址设置
【发布时间】: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


    【解决方案1】:

    如果您只关心回复是否发送到正确的邮箱,请将该电子邮件地址设置为回复地址。您可以使用Mailtem.ReplyRecipients.Add 来做到这一点。

    【讨论】:

      猜你喜欢
      • 2016-05-22
      • 2014-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-16
      • 2012-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多