gpt4 book ai didi

vba - 如何使用 Excel VBA 自动从 Thunderbird 发送电子邮件?

转载 作者:行者123 更新时间:2023-12-03 01:51:46 26 4
gpt4 key购买 nike

我想要做的是自动从 Thunderbird 帐户发送电子邮件。用户甚至不必点击电子邮件的“发送”按钮。

我尝试过使用 CDO,但问题是您必须输入要发送的帐户的用户名和密码。该宏将从多个不同的帐户中使用,因此输入每个用户名和密码是不可行的。如果有办法从 Thunderbird 检索用户名、密码和 smtp 服务器,我可以使用 CDO,但我觉得我已有的代码应该能够在没有 CDO 的情况下完成此任务(希望如此)。

这实际上是我看到的关于完成此操作的唯一代码(而且它无处不在)。

Sub Thunderbird()

Dim thund As String
Dim email As String
Dim cc As String
Dim bcc As String
Dim subj As String
Dim body As String

email = "email@test.com"
cc = "cc@test.com"
bcc = "bcc@test.com"
subj = "Subject"
body = "body text"

thund = "C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe"
thund = thund & " -compose " & Chr$(34) & "mailto:" & email & "?"
thund = thund & "cc=" & Chr$(34) & cc & "?"
thund = thund & "bcc=" & Chr$(34) & bcc & "?"
thund = thund & "subject=" & Chr$(34) & subj & Chr$(34)
thund = thund & "body=" & Chr$(34) & body

Call Shell(thund, vbNormalFocus)
SendKeys "^+{ENTER}", True

End Sub

截至目前,字段 ccbccsubjbody 均已正确识别。问题是它们都被添加到第一个字段的末尾。例如,按照现在的代码方式,cc 将放入 cc 字段,但 bccsubjbody 全部附加到 Thunderbird 的 cc 字段中的 cc 中。

如果我将 cc 注释掉,则 bcc 会放入正确的字段中,但 subjbody被附加到 Thunderbird 的 bcc 字段中的 bcc 中。

如果我注释掉ccbcc,那么subj就会被放入正确的字段,但是body被附加到 Thunderbird 主题字段中的 subj 中。

所以基本上我需要在每一行的末尾添加正确的代码。我已经尝试了 "?"Chr$(34) 均无济于事。

最后,SendKeys "^+{ENTER}", True 根本不起作用。这可能是因为所有参数都没有放入 Thunderbird 的正确字段中,但不确定,因为我无法使其正常工作。显示来自 Thunderbird 的电子邮件,但此代码并未像预期那样发送电子邮件。

解决方案(由@zedfoxus提供)

Sub Thunderbird()

Dim thund As String
Dim email As String
Dim cc As String
Dim bcc As String
Dim subj As String
Dim body As String

email = "email@test.com"
cc = "cc@test.com"
bcc = "bcc@test.com"
subj = "Subject"
body = "body text"

thund = "C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe" & _
" -compose " & """" & _
"to='" & email & "'," & _
"cc='" & cc & "'," & _
"bcc='" & bcc & "'," & _
"subject='" & subj & "'," & _
"body='" & body & "'" & """"

Call Shell(thund, vbNormalFocus)
Application.Wait (Now + TimeValue("0:00:03"))
SendKeys "^{ENTER}", True

End Sub

最佳答案

你们已经很接近了。试试这个:

Public Sub SendEmail()
Dim thund As String
Dim email As String
Dim cc As String
Dim bcc As String
Dim subj As String
Dim body As String

email = "test@test.com"
cc = "test@test.com"
bcc = "test@test.com"
subj = "Testing"
body = "Testing"

thund = "C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe " & _
"-compose " & """" & _
"to='" & email & "'," & _
"cc='" & cc & "'," & _
"bcc='" & bcc & "'," & _
"subject='" & subj & "'," & _
"body='" & body & "'" & """"

Call Shell(thund, vbNormalFocus)
SendKeys "^+{ENTER}", True

End Sub

注意 http://kb.mozillazine.org/Command_line_arguments_(Thunderbird) 中的示例.

thunderbird -compose "to='john@example.com,kathy@example.com',cc='britney@example.com',subject='dinner',body='How about dinner tonight?',attachment='C:\temp\info.doc,C:\temp\food.doc'"

该示例表明,在 -compose 之后,我们应该在双引号中键入我们的信息。每个参数以逗号分隔。命名法为 parameter='value[,value]' [,parameter='value[,value]]...

关于vba - 如何使用 Excel VBA 自动从 Thunderbird 发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39521872/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com