Topic Options
#57532 - 07/01/20 04:21 PM send html through
Tom@ECI Offline
OL Newbie

Registered: 04/20/10
Posts: 19
Loc: Fort Worth, Tx
We have this script below for sending emails SSL that we got from OL.
We have a need to replace the textbody below with a block of HTML. We were sending this HTML by using an Image plugin and put the message in the body, but we can't do that with SSL.
This message contains static data as well as data from the input file.
Is there a way that we can do something similar with the script? Can we/do we have to output the body text to a file, then call the file from the script?

Option explicit
Dim MyMsg
Set MyMsg = CreateObject("CDO.Message" )

'' Select one of the options below to meet your own settings

'' OPTION 1: Use port 25 for standard mail. Uncomment next line to use it
'' SMTPConfig MyMsg, "MySmtp.Server.Com", 25, "MyUserName", "MyUserPassword", False

'' OPTION 2: Use port 465 or 587 for SSL mail (e.g. Gmail uses 465 for SSL). Uncomment next line to use it
SMTPConfig MyMsg, "smtp.gmail.com", 465, Watch.GetVariable("username"), Watch.GetVariable("password"), True
''SMTPConfig MyMsg, "smtp.office365.com", 25, Watch.GetVariable("username"), Watch.GetVariable("password"), True

MyMsg.From = Watch.GetVariable("UserName")
''MyMsg.Sender = "test@test.com"
MyMsg.To = Watch.GetVariable("af_ToAddress")
MyMsg.Subject = Watch.GetVariable("af_Subject")
''MyMsg.Subject = "This is the subject of the email"
MyMsg.TextBody = Watch.GetVariable("af_Comment")
''MyMsg.TextBody = "This is the body of the email."

'' If you want to attach the job file, uncomment next line
MyMsg.AddAttachment Watch.GetJobFileName

MyMsg.Send


Sub SMTPConfig(msg, srv, port, user, pw,useSSL)
Const cdoFieldPrefix = "http://schemas.microsoft.com/cdo/configuration/"
with msg
.Configuration.Fields.Item (cdoFieldPrefix & "sendusing" ) = 2
.Configuration.Fields.Item (cdoFieldPrefix & "smtpserver" ) = srv
.Configuration.Fields.Item (cdoFieldPrefix & "smtpserverport" ) = port
.Configuration.Fields.Item (cdoFieldPrefix & "sendusername" ) = user
.Configuration.Fields.Item (cdoFieldPrefix & "sendpassword" ) = pw
.Configuration.Fields.Item (cdoFieldPrefix & "smtpauthenticate") = 1
.Configuration.Fields.Item (cdoFieldPrefix & "smtpusessl") = useSSL
'' .Configuration.Fields.Item (cdoFieldPrefix & "smtpuseTLS") = useSSL
.Configuration.Fields.Update
end with
end sub

Top
#57534 - 07/01/20 05:46 PM Re: send html through [Re: Tom@ECI]
jim3108 Online   content
OL Expert

Registered: 04/19/10
Posts: 311
Loc: London, UK
Technically, you could read any file of HTML markup into a string variable.

If you're reading from a file as you suggest, then load your file using a filesystem object.

Code:
Dim objFSO, objFile
Dim sFilePath, sFileContent

Const FOR_READING = 1

sFilePath = Watch.GetVariable("<PATH TO HTML MARKUP FILE>")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(sFilePath, FOR_READING)

sFileContent = objFile.ReadAll

' and so on....

Then you'd use the line:

Code:
MyMsg.TextBody = sFileContent

Please bear in mind I wrote this without a script editor so there may be syntax errors.

Hope this helps.

Regards,

James.

Top
#57543 - 07/02/20 10:40 AM Re: send html through [Re: jim3108]
Tom@ECI Offline
OL Newbie

Registered: 04/20/10
Posts: 19
Loc: Fort Worth, Tx
Hi James,
Thanks for your reply.

Below is what we're putting in the email body. If I'm understanding you, we would have to use an output to text like "body.txt".
Then in the script we would do:
sFilePath = Watch.GetVariable("c:\temp\body.txt")

Thanks,
Tom

Code:
<html>
<head>
    </head>
    <body>
        <div style="text-align: center;"><br />
        </div>
        <br />
        &nbsp;<br />
        It is time to submit your current meter reading for your copier. &nbsp;Meter readings not received by the 15th of each month will be estimated for billing.&nbsp;If you need assistance obtaining your meter reading, please contact our service department at _____________.&nbsp;<br />
        <br />
        Download the attached form and submit by fax or email.&nbsp;&nbsp;<br />
        <br />
        Service Department Fax: ___________<br />
        Email: __________________<br />
        <br />
        Please call with any questions. &nbsp;<br />
        <br />
        Thanks,<br />
        <br />
        _______________________<br />
        <br />
        @(1,11,11,6,30,KeepCase,NoTrim)<br />
        Attn:&nbsp;&nbsp;@(1,11,11,51,73,KeepCase,NoTrim)&nbsp;<br />
        <br />
        <br />
        <table>
            <tbody>
                <tr>
                    <td style="border:1px solid #366092;background-color: #31859b;">Make/Model&nbsp;</td>
                    <td style="border:1px solid #366092;background-color: #31859b;">ID # / <span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">Serial Number&nbsp;</span></td>
                    <td style="border:1px solid #366092;background-color: #31859b;">Meter &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</td>
                    <td style="border:1px solid #366092;background-color: #31859b;">Location</td>
                    <td style="border:1px solid #366092;background-color: #31859b;">Last Reading</td>
                    <td style="border:1px solid #366092;background-color: #31859b;">Current Reading&nbsp;</td>
                    <td style="border:1px solid #366092;background-color: #31859b;">Reading Date&nbsp;</td>
                </tr>
                <tr>
                    <td style="border:1px solid #366092;">&nbsp;<span style="font-size: 13px;">@(1,17,17,3,17,KeepCase,NoTrim)</span></td>
                    <td style="border:1px solid #366092;"><span style="font-size: x-small;">&nbsp;@(1,17,17,20,30,KeepCase,Trim)/@(1,17,17,34,47,KeepCase,Trim)</span></td>
                    <td style="border:1px solid #366092;"><span style="font-size: x-small;">&nbsp;Black/White</span></td>
                    <td style="border:1px solid #366092;"><span style="font-size: x-small;">&nbsp;@(1,17,19,55,73,KeepCase,NoTrim)</span></td>
                    <td style="border:1px solid #366092;"><span style="font-size: x-small;">&nbsp;@(1,22,22,78,86,KeepCase,NoTrim)</span></td>
                    <td style="border:1px solid #366092;"><span style="font-size: x-small;">&nbsp;</span></td>
                    <td style="border:1px solid #366092;"><span style="font-size: x-small;">&nbsp;</span></td>
                </tr>
            </tbody>
        </table>
    </body>
</html>

Top
#57551 - 07/02/20 05:31 PM Re: send html through [Re: Tom@ECI]
jim3108 Online   content
OL Expert

Registered: 04/19/10
Posts: 311
Loc: London, UK
Tom,

That's right.

Alternatively, if you have a dynamic HTML file or wish to add to it on the fly, you'd use a Create File plugin to create your HTML content and then pick up that file in the script using:
Code:
sFilePath = Watch.GetJobFilename


Let us know how you get on.

Regards,

James.

Top