将电子邮件保存到Outlook中的草稿文件夹

时间:2019-07-24 05:14:07

标签: excel vba outlook cdo.message

我已经具有发送电子邮件的代码,但是我不希望发送它,而只是希望将其保存在Outlook的草稿文件夹中。

我尝试添加.Close函数,但这种方法不起作用。有想法吗?

    Dim iCfg As CDO.Configuration
    Dim iMsg As CDO.message
    Dim EmailAddr As String
    Dim wsEmail As Worksheet
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("Forecast")
    Set wsEmail = ThisWorkbook.Worksheets("Recepient")

    Set iCfg = New CDO.Configuration
    With iCfg
        .Fields(cdoSMTPServer) = "XXX"
        .Fields(cdoSMTPServerPort) = 25
        .Fields(cdoSendUsingMethod) = cdoSendUsingPort
        .Fields(cdoSMTPConnectionTimeout) = 200
        .Fields.Update
    End With

    Set iMsg = New CDO.message
    With iMsg
        Set .Configuration = iCfg
        .To = Worksheets("Recepient").Cells(5, 2).Value
        .cc = Worksheets("Recepient").Cells(5, 3).Value
        .From = "Automated Notification <NoReplyEmail@agit.com>"
        .Subject = "OPEN REQUEST " & Format(Now, "dd-mmm-yyyy")
        .HTMLBody = strBodyStandard
        .Close (olsave)
    End With

    Set iMsg = Nothing
    Set iCfg = Nothing
End Sub

2 个答案:

答案 0 :(得分:0)

使用:

.Close olSave

enter image description here

代替:

.Close

olSave会将邮件保存在“草稿文件夹”中


您的代码:

    With iMsg
        Set .Configuration = iCfg
        .To = Worksheets("Recepient").Cells(5, 2).Value
        .cc = Worksheets("Recepient").Cells(5, 3).Value
        .From = "Automated Notification <NoReplyEmail@agit.com>"
        .Subject = "OPEN  REQUEST " & Format(Now, "dd-mmm-yyyy")
        .HTMLBody = strBodyStandard
        .Close olSave
        '.Send
    End With

答案 1 :(得分:0)

CDO不提供任何Save方法。而且,这是一项非常古老的技术,如今已不再使用。相反,我建议使用提供Save方法的Outlook对象模型。您可能会发现以下文章很有帮助: