使用Excel VBA从Thunderbird自动发送电子邮件

我想要做的就是自动从Thunderbird账户发送邮件。 用户甚至不必点击电子邮件的发送button。

我尝试过使用CDO,但问题在于您必须input您要发送的帐户的用户名和密码。 这个macros将被用于几个不同的帐户,所以input每个用户名和密码是不可行的。 如果有人从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的电子邮件显示,但是这个代码并没有发送像它应该的电子邮件。

解决scheme (由@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 ='今晚的晚餐怎么样?',attachment ='C :\ TEMP \ info.doc,C:\ TEMP \ food.doc'”

这个例子表明,组合后,我们应该使用双引号input我们的信息。 每个参数用逗号分隔。 命名法是parameter='value[,value]' [,parameter='value[,value]]...