从Excel发送Outlook电子邮件

时间:2018-02-14 09:02:48

标签: excel excel-vba excel-2010 excel-2007 vba

我有以下发送电子邮件的VBA:

    With Sendrng

        ' Select the worksheet with the range you want to send
        .Parent.Select

        'Remember the ActiveCell on that worksheet
        Set rng = ActiveCell

        'Select the range you want to mail
        .Select

        ' Create the mail and send it
        ActiveWorkbook.EnvelopeVisible = True
        With .Parent.MailEnvelope

            ' Set the optional introduction field thats adds
            ' some header text to the email body.
            .Introduction = ""

            With .Item
                .To = "123@321.com"
                .CC = ""
                .BCC = ""
                .Subject = "A new deli pre-order has been received."
                .Send
            End With

我现在正在努力的部分是设置电子邮件的来源

我认为添加以下内容可行:

 .From = "111@222.com"

添加上述内容时会发生什么: 根本没有收到任何电子邮件

我错过了什么?

3 个答案:

答案 0 :(得分:1)

您可以尝试.SendUsingAccount选择要发送电子邮件的帐户。

With .Item
    .SendUsingAccount = olAccount 'or some other account.
    .To = "123@321.com"
    .CC = ""
    .BCC = ""
    .Subject = "A new deli pre-order has been received."
    .Send
End With

答案 1 :(得分:0)

您可能正在寻找.SenderEmailAddress.SentOnBehalfOfName

答案 2 :(得分:-1)

以这种方式试试。

Sub Mail_workbook_Outlook_1()
'Working in Excel 2000-2016
'This example send the last saved version of the Activeworkbook
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
    Dim OutApp As Object
    Dim OutMail As Object

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
        .to = "ron@debruin.nl"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = "Hi there"
        .Attachments.Add ActiveWorkbook.FullName
        'You can add other files also like this
        '.Attachments.Add ("C:\test.txt")
        .Send   'or use .Display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

https://www.rondebruin.nl/win/s1/outlook/amail1.htm

相关问题