I'm trying to send email from a visual basic script using Visual basic WITHOUT any user action. The idea came for the first reference below.
http://forums.mozillazine.org/viewtopic.php?f=39&t=540783
http://forums.mozillazine.org/viewtopic.php?t=203591
https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#-options
The script does work BUT I have been unable to figure out how to include attachments. I know little about VB but in the first reference the mixture of " and chr(34) (" I assume) seems very weird. Also the discrepancy between "mailto" and "to" between the first and third reference is troubling.
Here's what I have tried.
dim s
Set s = CreateObject("WScript.Shell")
s.run """thunderbird.exe""" & " -compose mailto:mdorl@wisc.edu? &subject=""send mail 3""&body=""nice body text""&attachment='file:///c:/Documents and Settings/Mike/My Documents/sendmail/vb/msg.txt'"
WScript.Sleep 1000
s.SendKeys "^{ENTER}"
WScript.Sleep 1000
This composes and sends an email without user action BUT without the attachment. I have tried both single and double quotes around the file name.
If I change the file name to a non-existent file, an email is send without attachment BUT user action is required to actually send the message.
edited my answer since I've been learning a thing or two these last couple of weeks ;)
you need an apostrophe around to: and cc: lists with more than one recipient
you also need an apostrophe around any main body text or attachments you're going to send
if you put an apostrophe into your VBA editor, it just comments it out, so you can get away with that by using Chr(39)
also, as the documentation suggests, you need
attachment='file:///c:/test.txt'
which includes the file:///
I've included an example from something I've been working on below
Dim reportTB As Object
Set reportTB = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
reportTB.Run "thunderbird.exe -compose to=bfx_" & LCase(show) & "prod@base-fx.com,subject=[" & show & "] EOD Report " _
& prjDate & ",body=" & Chr(39) & "Hi " & UCase(show) & "ers,<br><br>Today's end of day report is attached.<br>" & _
"Any questions let me know.<br><br>Edi " & Chr(39) & ",attachment=" & Chr(39) & reportPath & Chr(39), windowStyle, waitOnReturn
Hope that helps :)
Write proper programs. You can't send attachments with mailto. The standard only allows one parameter (although everyone accepts many).
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "dc@gmail.com"
emailObj.To = "dc@gmail.com"
emailObj.Subject = "Test CDO"
emailObj.TextBody = "Test CDO"
emailObj.AddAttachment "C:/Users/User/Desktop/err.fff"
Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "dc"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Password1"
emailConfig.Fields.Update
emailObj.Send
If err.number = 0 then
Msgbox "Done"
Else
Msgbox err.number & " " & err.description
err.clear
End If