
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi David,
Email is email. The main issue that folks run into with GMail is the authentication, which not all SMTP servers have. If you are planning on running all your outbound email via GMail, then the example scripts do the trick.
If you wish to use multiple SMTP servers to send email for some reason (which is unusual), you can make the server addressing and other server details configurable. The second link, which I am repeating here, shows quite clearly how you set up the SMTP server address.
My company is using a variation of this script to send application-generated email with large To lists and with attachments, using a standard (not GMail) SMTP host. I had it up and running in less than a day. I was not new to VBScript, but did need to learn about the details of using CDO.
Tom Morrison
Consultant

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
RE: Email using GMAIL with TLS
Since you refer specifically to VBScript, I presume you have seen and rejected this approach:
community.microfocus.com/.../10743.aspx
I can almost guarantee you that you will have a VBScript based solution running before you can even assemble all the knowledge you need for creating a COBOL TLS solution for GMail. There are several VBScript tutorials available on the web to help you get started.
Tom Morrison
Consultant

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
RE: Email using GMAIL with TLS
Thanks Tom for the quick reply. I was hoping I would not have to learn anything new right now but you know!!!!
Would the VBScript option be used for all email or just GMAIL?
Thanks,
David

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi David,
Email is email. The main issue that folks run into with GMail is the authentication, which not all SMTP servers have. If you are planning on running all your outbound email via GMail, then the example scripts do the trick.
If you wish to use multiple SMTP servers to send email for some reason (which is unusual), you can make the server addressing and other server details configurable. The second link, which I am repeating here, shows quite clearly how you set up the SMTP server address.
My company is using a variation of this script to send application-generated email with large To lists and with attachments, using a standard (not GMail) SMTP host. I had it up and running in less than a day. I was not new to VBScript, but did need to learn about the details of using CDO.
Tom Morrison
Consultant

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
RE: Email using GMAIL with TLS
Thanks Tom for your responses. All my customers do not use GMAIL. That is exactly how I have written my system - configurable. I believe that the CDO option would be best since we are sending many emails with attachments. I just wished C$Socket would have worked since I already had that working for email that did not require TLS.
Thanks again,
David

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
RE: Email using GMAIL with TLS
Enjoy.
'' sendmailxml.vbs parameters.xml [/delete:both|msg|parms] [/log:logfilename]
''
'' Logging is to the optional logfilename
'' Specify /delete:both to delete BOTH the parameters.xml file and the message file
'' Specify /delete:msg to delete only the message file
'' Specify /delete:parms to delete only the parameters.xml file
'' Nothing deleted if error; attachments are NOT deleted
''
Const forReading = 1
Const forWriting = 2
Const forAppending = 8
Dim objArgs, fso, theFile, strMessage, strBcc
Set fso = CreateObject("Scripting.FileSystemObject")
Set objUnamedArgs = Wscript.Arguments.Unnamed
Set objNamedArgs = Wscript.Arguments.Named
If objNamedArgs.Exists("log") Then
If fso.FileExists(objNamedArgs("log")) Then
Set logfile = fso.OpenTextFile(objNamedArgs("log"), forAppending)
Else
Set logfile = fso.CreateTextFile(objNamedArgs("log"))
End If
Else
Set logfile = Null
End If
strDelete = "NO"
If objNamedArgs.Exists("delete") Then strDelete = UCase(objNamedArgs("delete"))
If Not IsNull(logfile) Then logfile.WriteLine chr(013) & chr(010) & "sendmailxml invoked at " & Now()
strParmsFilename = objUnamedArgs(0)
strAbsFilename = fso.GetAbsolutePathName(strParmsFilename)
If Not IsNull(logfile) Then logfile.WriteLine "Parms: " & strAbsFilename
Set XMLParms = CreateObject("Microsoft.XMLDOM")
XMLParms.async = false
XMLParms.load(strAbsFilename)
If XMLParms.parseError.errorCode <> 0 Then
Set myErr = XMLParms.parseError
If Not IsNull(logfile) Then logfile.WriteLine "Parse error: " + myErr.Reason
WScript.Quit
End If
strErrorFound = "NO"
If objUnamedArgs.Count > 1 Then
If UCase(objUnamedArgs(1)) = "DELETE" Then strDelete = UCase(objUnamedArgs(1))
End If
strTo = ""
strComma = ""
Set Nodes = XMLParms.documentElement.SelectNodes("//to")
For i = 0 To Nodes.Length - 1
strTo = strTo & strComma & Nodes(i).Text
strComma = ","
Next
strBCC = ""
strComma = ""
Set Nodes = XMLParms.documentElement.SelectNodes("//bcc")
For i = 0 To Nodes.Length - 1
strBCC = strBCC & strComma & Nodes(i).Text
strComma = ","
Next
Set Nodes = XMLParms.documentElement.SelectNodes("//account")
If Nodes.Length = 1 Then
strAccountID = Nodes(0).Text
Else
strAccountID = "No Account or multiple accounts found."
strErrorFound = "YES"
End If
Set Nodes = XMLParms.documentElement.SelectNodes("//pw")
If Nodes.Length = 1 Then
strPassword = Nodes(0).Text
Else
strPassword = "No Password or multiple passwords found."
strErrorFound = "YES"
End If
Set Nodes = XMLParms.documentElement.SelectNodes("//smtp-server")
If Nodes.Length = 1 Then
strSMTPServer = Nodes(0).Text
Else
strSMTPServer = "No smtp-server or multiple smtp-server found."
strErrorFound = "YES"
End If
Set Nodes = XMLParms.documentElement.SelectNodes("//smtp-port")
If Nodes.Length = 1 Then
smtpServerPort = Nodes(0).Text
Else
smtpServerPort = "No smtp-port or multiple smtp-port found."
strErrorFound = "YES"
End If
Set Nodes = XMLParms.documentElement.SelectNodes("//subject")
If Nodes.Length = 1 Then
strSubject = Nodes(0).Text
Else
strSubject = "No Subject"
End If
Set Nodes = XMLParms.documentElement.SelectNodes("//from")
If Nodes.Length = 1 Then
strFrom = Nodes(0).Text
Else
strFrom = "No From or multiple from found."
strErrorFound = "YES"
End If
strSender = ""
Set Nodes = XMLParms.documentElement.SelectNodes("//sender")
If Nodes.Length = 1 Then strSender = Nodes(0).Text
Set Nodes = XMLParms.documentElement.SelectNodes("//message-file")
If Nodes.Length = 1 Then
strMessageFilename = Nodes(0).Text
Else
strMessageFilename = "No message-file or multiple message-file found."
strErrorFound = "YES"
End If
If Not IsNull(logfile) Then logfile.WriteLine "From: " & strFrom
If Not IsNull(logfile) Then logfile.WriteLine "Sender: " & strSender
If Not IsNull(logfile) Then logfile.WriteLine "To: " & strTo
If Not IsNull(logfile) Then logfile.WriteLine "Bcc: " & strBCC
If Not IsNull(logfile) Then logfile.WriteLine "Subject: " & strSubject
If Not IsNull(logfile) Then logfile.WriteLine "Account: " & strAccountID
If Not IsNull(logfile) Then logfile.WriteLine "Passwd: " & String(Len(strPassword), "*")
If Not IsNull(logfile) Then logfile.WriteLine "SMTP Srv:" & strSMTPServer
If Not IsNull(logfile) Then logfile.WriteLine "Port: " & CStr(smtpServerPort)
If Not IsNull(logfile) Then logfile.WriteLine "MsgFile: " & CStr(strMessageFilename)
If strErrorFound = "YES" Then
If Not IsNull(logfile) Then logfile.WriteLine "Error processing parameters. No connection attempt."
WScript.Quit
End If
Set theFile = fso.OpenTextFile(strMessageFilename, forReading)
If theFile.AtEndOfStream Then
strMessage = ""
Else
strMessage = theFile.ReadAll
End If
theFile.Close
strNewText = Replace(strMessage, chr(013) & chr(010), " ") ' chr(010) = line feed chr(013) = carriage return
If Not IsNull(logfile) Then logfile.WriteLine "Msg: " & Left(strNewText,20) & "<..>" & Right(strNewText,20) & "(" & CStr(Len(strMessage)) & ")"
Set oEmail = CreateObject("CDO.Message")
'configure message
With oEmail.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPServer
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = smtpServerPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = strAccountID
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strPassword
.Update
End With
' build message
With oEmail
.From = strFrom
.Sender = strSender
.To = strTo
.Bcc = strBCC
.Subject = strSubject
.TextBody = strMessage
End With
Set Nodes = XMLParms.documentElement.SelectNodes("//attachment-file")
For i = 0 To Nodes.Length - 1
strAttachFile = fso.GetAbsolutePathName(Nodes(i).Text)
If Not IsNull(logfile) Then logfile.WriteLine "Attach: " & strAttachFile
oEmail.AddAttachment strAttachFile
Next
If strDelete = "BOTH" or strDelete = "PARMS" or strDelete = "MSG" Then
If Not IsNull(logfile) Then logfile.WriteLine "DelMode: " & strDelete
End If
If strDelete = "BOTH" or strDelete = "PARMS" Then
If Not IsNull(logfile) Then logfile.WriteLine "Delete: " & strAbsFilename
fso.DeleteFile(strAbsFilename)
End If
If strDelete = "BOTH" or strDelete = "MSG" Then
strMsgFileForDelete = fso.GetAbsolutePathName(strMessageFilename)
If Not IsNull(logfile) Then logfile.WriteLine "Delete: " & strMsgFileForDelete
fso.DeleteFile(strMsgFileForDelete)
End If
' send message
On Error Resume Next
oEmail.Send
If Err Then
If Not IsNull(logfile) Then logfile.WriteLine "SendMail Failed:" & Err.Description
End If
If Not IsNull(logfile) Then logfile.WriteLine "sendmailxml complete at " & Now()
Tom Morrison
Consultant

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
RE: Email using GMAIL with TLS
Thanks Tom!
Since I am new to all this VBScript and CDO functionality how would I actually run this using parameters from my program?
I know I can use the system command to run the sendmailxml.vbs. Would they be parameters after the sendmailxml.vbs?
Thanks,
David

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
RE: Email using GMAIL with TLS
Hi David,
I cannot tell you exactly what you need to do in AcuCOBOL, since I am an RM/COBOL user. In the forum thread I referenced above, there was some discussion. In RM/COBOL I use:
MOVE SPACES TO CMD-LINE
STRING 'cmd.exe /c sendmailxml.vbs "' delimited by size
XML-PATHNAME delimited by space *> I make sure there are no spaces in the name
'" /delete:both /log:"' delimited by size
LOG-PATHNAME delimited by space
'"' delimited by size
INTO CMD-LINE
CALL "SYSTEM" USING CMD-LINE
The comments at the top of the script describe the command parameters. On RM/COBOL, I use XML Extensions to export the parameter document to a temporary file (the pathname of which is in XML-PATHNAME), then pass that filename as a parameter to the VBScript.as shown above. I use a parameter document because (1) exporting is so easy using XML Extensions, (2) the parameters are really too complex for a command line, even with named parameters available, and (3) processing an XML document on the VBScript side is also quite easy. The parameters that I put in the parameter document include everything I need for assembling the email message.
Executing a VBScript file is very similar to executing a .BAT file.
Tom Morrison
Consultant

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
RE: Email using GMAIL with TLS
That helped a lot.
Would you have an example of what the parameter document would look like?
Thanks,
David

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
RE: Email using GMAIL with TLS
this will give you an idea...
<?xml version="1.0" encoding="utf-8"?>
<parameters>
<from>"Bubba" <abcd@domain,net></from>
<account>11.12.13.14</account>
<pw>password</pw>
<smtp-server>your smtp server ip address</smtp-server>
<smtp-port>25</smtp-port>
<subject>Test Message</subject>
<message-file>msg-e99567ba-da38-42a2-b247-2e690bd99bf0.txt</message-file>
<to>JoeDoe@doe.com</to>
<bcc>aard@vark.us</bcc>
<attachment-file>image1.jpg</attachment-file>
<attachment-file>image2.jpg</attachment-file>
</parameters>
Tom Morrison
Consultant

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
RE: Email using GMAIL with TLS
That is awesome. I can create the parameter file from saved data. I do appreciate all you have provided me.
Thanks for answering my questions. If you need anything don't hesitate to ask.
Thanks,
David

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
RE: Email using GMAIL with TLS
David, a final note.
Don't forget that my script has not been adapted to the needs of GMail. You should go look at those other scripts to see the extra bits GMail requires.
Welcome to the wonderful world of VBScript. I must admit that I use it quite a bit, since it allows me to get to a lot of prepackaged .NET functionality with a Google's worth of examples to be found by search. We had been using .BAT for a long time, and I am now pursuing using PowerShell so I can use Cmdlets. So, you can see it has been an evolution for me - but it lets me get the job done without too much struggle.
Tom Morrison
Consultant

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
RE: Email using GMAIL with TLS
I will do that. You are very much appreciated.
Thanks,
David