自动发送电子邮件从雷鸟与Excel VBA
我想要做的就是自动从Thunderbird帐户发送电子邮件。用户甚至不必点击电子邮件的发送按钮。自动发送电子邮件从雷鸟与Excel VBA
我试过使用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 protected]"
cc = "[email protected]"
bcc = "[email protected]"
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
截至目前,该领域cc
,bcc
,subj
和body
都是正确识别。问题是他们都被添加到第一个字段的末尾。例如,现在代码的方式,cc
将被放入cc字段,但bcc
,subj
和body
都会被附加到Thunderbird的cc字段中的cc
。
如果我评论cc
出来,然后bcc
被放在正确的领域,但subj
和body
获得雷鸟的密件抄送字段添加到bcc
。
如果我评论cc
和bcc
出来,然后subj
被放置在正确的领域,但body
获取雷鸟的主题字段添加到subj
。
所以基本上我需要在每一行的末尾添加正确的代码。我试过"?"
和Chr$(34)
都无济于事。
最后,SendKeys "^+{ENTER}", True
根本不起作用。这可能是因为没有将所有参数放在Thunderbird的正确字段中,但不确定,因为我无法正常工作。来自Thunderbird的电子邮件会显示,但此代码并不像发送电子邮件那样发送。
SOLUTION(由@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 protected]"
cc = "[email protected]"
bcc = "[email protected]"
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 = "[email protected]"
cc = "[email protected]"
bcc = "[email protected]"
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 ='今晚的晚餐怎么样? ”,附件= 'C:\ TEMP \ info.doc,C:\ TEMP \ food.doc'”
的例子表明,-compose
后,我们应该用我们的输入双引号的信息。每个参数用逗号分隔。命名是parameter='value[,value]' [,parameter='value[,value]]...
。
谢谢!不幸的是,SendKeys位仍然不起作用。电子邮件显示正确,但SendKeys不会发送电子邮件。它实际上只是最小化窗口。 – user2951249
你有什么版本的Windows?你有什么版本的Excel?我有Office 365 ProPlus和SendKeys与Windows 7上的Thunderbird完美配合。 – zedfoxus
试试'Application.SendKeys“%fl”,True'而不是'SendKeys“^ + {ENTER}”,True'。如果这不起作用,请尝试'SendKeys“^ +〜”,True' – zedfoxus
[通过Thunderbird发送Excel宏](https:// stackoverflow。com/questions/31283948/excel-macro-sending-thunderbird/31284639#31284639) – 0m3r