将带有附件的电子邮件转发给所有收件人

时间:2018-11-07 15:13:27

标签: vba email outlook

我收到包含Excel报告作为附件的电子邮件。它们都来自同一发件人,但每封电子邮件都有不同的收件人。

一个例子:

电子邮件#1

  

发件人:John@gmail.com收件人:me@gmail.com; mike@gmail.com

     

+1个附件Excel文件

电子邮件#2

  

来自:John@gmail.com到:me@gmail.com; jessica@gmail.com

     

+1个附件Excel文件

我需要使用附件将这些电子邮件再次转发给收件人。

1 个答案:

答案 0 :(得分:-1)

当您收到来自特定发件人的电子邮件时,可以运行一个脚本来创建macro rule。 关于自动保存附件,请参考以下代码:

 Sub Save_Attachment(olItem As Outlook.MailItem)
        Dim olAttch As Outlook.attachment
        Dim sPath As String
        Dim acount
        Dim objMsg As MailItem
        Dim recips As Outlook.Recipients
        Dim recip As Outlook.Recipient

    For Each olAttch In olItem.Attachments
           If olAttch.UnRead = True Then
                If olAttch.SenderEmailAddress = "v-shuail@microsoft.com" Then
                    Set acount = olAttch.Attachments.Count
                    If acount > 0 Then
                        Set objMsg = Application.CreateItem(olMailItem)
                        Set recips = olAttch.Recipients


                        With objMsg
                          .Subject = "This is the subject"
                          .Attachments.Add ("path-to-file.docx")
                           For Each recip In recips
                            .Recipients.Add (recip)
                           Next
                          .Send
                        End With
                        Set objMsg = Nothing
                    End If
                End If
            End If
        Next

        Set olAttch = Nothing

End Sub