Access 2007 VBa using Thunderbird Mail (1 Viewer)

bleakhouse

New member
Local time
Today, 02:05
Joined
Mar 7, 2019
Messages
13
Hi


I am wanting some code for sending email using thunderbird as my mail client instead of outlook currently used. My hosting provider suggests I use Thunderbird to overcome a problem. My current system works ok, I just need to change the settings to Thunderbird


Thanks in anticipation


Best Regards
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:05
Joined
Oct 29, 2018
Messages
21,358
Hi. What happens if you use the SendObject method?
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:05
Joined
Sep 21, 2011
Messages
14,048
My hosting provider suggests I use Thunderbird to overcome a problem. My current system works ok, I just need to change the settings to Thunderbird

That sounds like a cop out. :D

What problem are you having, as I use 2007 and Outlook as well.
 

bleakhouse

New member
Local time
Today, 02:05
Joined
Mar 7, 2019
Messages
13
I havn't got a problem, but my email hoster TSHosts has updated the encryption settings for my email service. Outlook 2007 does not recognise them and they recommended using Thunderbird as a solution.


The enquiry and email system that we use has been working fine for the last 10 years with no problems.


I have also a colleague who can only use Thunderbird as on his laptop he has office365 supplied by the company he works for, this is another reason for wanting to convert the system to using Thunderbird.


Regards
 

bastanu

AWF VIP
Local time
Yesterday, 19:05
Joined
Apr 13, 2010
Messages
1,401
Here is what I used, mind you was about 10 years ago:
Code:
Option Compare Database
Option Explicit

Declare Function apiShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) _
    As Long

'***App Window Constants***
Public Const WIN_NORMAL = 1         'Open Normal
Public Const WIN_MAX = 3            'Open Maximized
Public Const WIN_MIN = 2            'Open Minimized

'***Error Codes***
Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&        'Open Normal

Public Function vcSendThunderbird(strTo As String, strSubject As String, strBody As String, strFile As String)
     
     'This function can be used to send an e-mail from Mozilla Thunderbird.
       '
    Dim strCommand As String
    
    strFile = "file:///" & strFile & ""
    
    If InStr(GetDefaultEmailProgramName, "hunderbird") > 0 Then
        strCommand = GetDefaultEmailProgramPath & GetDefaultEmailProgramName
    Else
        strCommand = "C:\Program Files\Mozilla Thunderbird\thunderbird"
    End If
    'strCommand = "C:\Program Files\Mozilla Thunderbird\thunderbird"
     
    strCommand = strCommand & " -compose to=" & strTo & Chr$(34) & ","
    strCommand = strCommand & "subject=" & Chr$(34) & strSubject & Chr$(34) & ","
    strCommand = strCommand & "body=" & Chr$(34) & strBody & Chr$(34) & ","
    strCommand = strCommand & "attachment=" & Chr$(34) & strFile & Chr$(34) & ""
 
    Call Shell(strCommand, vbNormalFocus)
     
End Function
Public Function vcSendThunderbirdwithBCC(strTo As String, strBCC As String, strSubject As String, strBody As String, strFile As String)
     
     'This function can be used to send an e-mail from Mozilla Thunderbird.
       '
    Dim strCommand As String
    strFile = "file:///" & strFile & ""
     
    
    If GetDefaultEmailProgramPath = "Thunderbird" Then
        strCommand = GetDefaultEmailProgramPath & GetDefaultEmailProgramPath
    Else
        strCommand = "C:\Program Files\Mozilla Thunderbird\thunderbird"
    End If
    strCommand = strCommand & " -compose to=" & strTo & Chr$(34) & ","
    strCommand = strCommand & "bcc=" & strBCC & Chr$(34) & ","
    strCommand = strCommand & "subject=" & Chr$(34) & strSubject & Chr$(34) & ","
    strCommand = strCommand & "body=" & Chr$(34) & strBody & Chr$(34) & ","
    strCommand = strCommand & "attachment=" & Chr$(34) & strFile & Chr$(34) & ""
 
    Call Shell(strCommand, vbNormalFocus)
     
End Function
Function GetDefaultEmailProgramName() As String
    'Written: November 30, 2008
    'Author:  Leith Ross
    'Summary: Function returns the name of the default email program.
    '         This works with Excel 2000 and up.

    Dim DefaultEmail As String
    Dim i As Long
    Dim ProgPath As Variant
    Dim WSH As Object

    Set WSH = CreateObject("WScript.Shell")

    DefaultEmail = WSH.RegRead("HKCR\mailto\shell\open\command\")
   
    i = InStr(2, DefaultEmail, Chr$(34))
    DefaultEmail = Mid(DefaultEmail, 2, i - 2)

    'This separates the email program name from the full path
    ProgPath = Split(DefaultEmail, "\")

    GetDefaultEmailProgramName = (ProgPath(UBound(ProgPath)))
'GetDefaultEmailProgramName = Replace(GetDefaultEmailProgramName, ".exe", "")
    Set WSH = Nothing

End Function
Function GetDefaultEmailProgramPath() As String
    'Written: November 30, 2008
    'Author:  Leith Ross
    'Summary: Function returns the name of the default email program.
    '         This works with Excel 2000 and up.

    Dim DefaultEmail As String
    Dim i As Long
    Dim ProgPath As Variant
    Dim WSH As Object

    Set WSH = CreateObject("WScript.Shell")

    DefaultEmail = WSH.RegRead("HKCR\mailto\shell\open\command\")
   
    i = InStr(2, DefaultEmail, Chr$(34))
    DefaultEmail = Mid(DefaultEmail, 2, i - 2)

    'This separates the email program name from the full path
    ProgPath = Split(DefaultEmail, "\")

    GetDefaultEmailProgramPath = Replace(DefaultEmail, ProgPath(UBound(ProgPath)), "")

    Set WSH = Nothing

End Function

To use it:

Call vcSendThunderbird(strToEmailAddress, strSubject, strMessageBody, sFileAttachment)

Cheers,
Vlad
 

bleakhouse

New member
Local time
Today, 02:05
Joined
Mar 7, 2019
Messages
13
Thanks for All the help


The solution I used was the excel example, however the wait statement was not recognised so I substituted a counter loop to 10000 and that fixed it.


I need to work out how to add 4 sometimes 5 attachments automatically.


Thanks again


Ian
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 21:05
Joined
Feb 28, 2001
Messages
27,001
bleakhouse, you can search this forum for threads discussing attachments. We have had more than one in the past three months and I'm sure of even more if you go back more than that.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:05
Joined
Oct 29, 2018
Messages
21,358
Thanks for All the help

The solution I used was the excel example, however the wait statement was not recognised so I substituted a counter loop to 10000 and that fixed it.

I need to work out how to add 4 sometimes 5 attachments automatically.

Thanks again

Ian
Hi Ian. Glad to hear you got it all sorted out. But, I was just curious. Since I don't have Thunderbird installed, if it's your default email client now, can you please verify for me that using SendObject doesn't open up Thunderbird for you? Thanks.
 

Hello1

Registered User.
Local time
Today, 04:05
Joined
May 17, 2015
Messages
271
I tired once to use Thunderbird for emailing but the problem I faced was the wait before the "SendKeys "^{ENTER}", True". It works well for few emails but if you are sending many at once but separately it gets problematic. When sending many the opening slows down and then the "SendKeys "^{ENTER}", True" happens earlier or later and things mess up. At least thats what I remember, I would like to hear your experience with it and for what particularly are you using it, just few emails or are there more?
 

bleakhouse

New member
Local time
Today, 02:05
Joined
Mar 7, 2019
Messages
13
I replaced the wait statement with a counter to 10000


For counter1 = 1 To 10000
Next


That worked for me


Regards
 

Users who are viewing this thread

Top Bottom