vba 从 Excel 宏创建 Thunderbird 电子邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14505852/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:20:07  来源:igfitidea点击:

Create Thunderbird email from Excel macro

excelemailvbaexcel-vbathunderbird

提问by user1934821

I have written a VB macro in Excel which creates and sends an email using MS Outlook.

我在 Excel 中编写了一个 VB 宏,它使用 MS Outlook 创建和发送电子邮件。

So I create an Outlook.Application, and then create an Outlook.Application.CreateItem(olMailItem).

所以我创建一个Outlook.Application,然后创建一个Outlook.Application.CreateItem(olMailItem).

This all works fantastically :) But now I have realized the machine I wanted to deploy it on does not have Outlook, and getting a licensed copy of Outlook is not an option. So how can I make this send an email through Thunderbird instead?

这一切都非常有效 :) 但是现在我意识到我想要部署它的机器没有 Outlook,并且无法获得 Outlook 的许可副本。那么我怎样才能让它通过 Thunderbird 发送电子邮件呢?

I can launch the application using this:

我可以使用这个启动应用程序:

Dim RetVal
RetVal = Shell("C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe", 1)

But I'm not sure how I can create a mail item for it. It does not need to use Thunderbird specifically, I just picked it because it was a free mail client.

但我不确定如何为其创建邮件项目。它不需要专门使用 Thunderbird,我只是因为它是一个免费的邮件客户端而选择它。

回答by niton

Is CDO not an option? http://www.rondebruin.nl/win/s1/cdo.htm– Siddharth Rout

CDO 不是一种选择吗?http://www.rondebruin.nl/win/s1/cdo.htm– 悉达多溃败

Sub CDO_Mail_Small_Text()
    Dim iMsg As Object
    Dim iConf As Object
    Dim strbody As String
    '    Dim Flds As Variant

    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")

    '    iConf.Load -1    ' CDO Source Defaults
    '    Set Flds = iConf.Fields
    '    With Flds
    '        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    '        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
    '                       = "Fill in your SMTP server here"
    '        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    '        .Update
    '    End With

    strbody = "Hi there" & vbNewLine & vbNewLine & _
              "This is line 1" & vbNewLine & _
              "This is line 2" & vbNewLine & _
              "This is line 3" & vbNewLine & _
              "This is line 4"

    With iMsg
        Set .Configuration = iConf
        .To = ""
        .CC = ""
        .BCC = ""
        .From = ""
        .Subject = "New figures"
        .TextBody = strbody
        .Send
    End With

End Sub 

Note: If you get this error : The transport failed to connect to the server then try to change the SMTP port from 25 to 465

注意:如果您收到此错误:传输无法连接到服务器,请尝试将 SMTP 端口从 25 更改为 465