2013-01-24 160 views
1

我已經在Excel中編寫了一個VB宏,它使用MS Outlook創建和發送電子郵件。從Excel宏創建Thunderbird電子郵件

因此,我創建了一個Outlook.Application,然後創建Outlook.Application.CreateItem(olMailItem)

這一切都很奇妙:)但現在我已經意識到我想部署它的機器沒有Outlook,並且獲得Outlook的許可副本不是一種選擇。那麼我怎麼才能讓這個郵件通過Thunderbird發送呢?

我可以啓動使用這個應用程序:

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

但我不知道我怎樣才能爲它創建一個郵件項目。它不需要專門使用Thunderbird,我只是選擇它,因爲它是一個免費的郵件客戶端。

+1

是CDO不是一種選擇? http://www.rondebruin.nl/cdo.htm –

+0

是的,這是完美的作品!感謝:D – user1934821

回答

1

CDO不是一個選項嗎? http://www.rondebruin.nl/win/s1/cdo.htm - 亞洲時報Siddharth潰敗

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 

注:如果您收到此錯誤:運輸未能連接到服務器,然後嘗試從25 SMTP端口更改爲465