Devart Blog

How To: Automatically Email Comparison Report

Posted by on September 9th, 2014

dbForge Studio for MySQL allows you to automate report creation process by using command line utility. There is a simple way to send comparison reports automatically via email.

To accomplish this task we will use the Collaboration Data Objects (CDO), previously known as OLE Messaging or Active Messaging. CDO is an application programming interface included with Microsoft Windows.

Below is the simple BAT file that automatically saves a comparison report in the HTML format on the “D:\\” drive and runs the send.vbs script file.

call “C:\Program Files\Devart\dbForge Studio for MySQL\dbforgemysql.com” /datacompare /compfile:d:\project.dcomp /reportformat:HTML /report:d:\report.html
start send.vbs

 

The send.vbs script contains essential settings that are important for the automatic email delivery:

  • Const mAttachment – report file name.
  • Const mFrom – sender email address
  • Const mTo – recipient email address
  • Const mSubject – email subject
  • Const mTextBody – email text
  • Const mSMTPServer – SMTP server name
  • Const mSMTPport – SMTP server port
  • oEmail- contains the CDO object
  • mReportDir – a directory that contains the report file

 

Entirely the send.vbs script looks as follows:

‘ Script Name: Send.vbs
‘ Date: 05.09.2014
‘ Author: Devart Team www.devart.com
‘ Description:
Option Explicit
On Error Resume Next
Dim mReportDir
Dim oShell, oEmail
Const mAttachment = “report.html” ‘
Const mFrom = “email_from@domain.com”
Const mTo = “email_to@domain.com”
Const mSubject = “Data Compare Report”
Const mTextBody = “See report…”
Const mSMTPServer = “SMTPserverIP_NAME”‘
Const mSMTPport = 25
Set oShell = CreateObject(“WScript.Shell”)
Set oEmail = CreateObject(“CDO.Message”)
mReportDir = “d:\”
oEmail.From = mFrom
oEmail.To = mTo
oEmail.Subject = mSubject
oEmail.Textbody = mTextBody
Call oEmail.AddAttachment(mReportDir & mAttachment)
oEmail.Configuration.Fields.Item (“http://schemas.microsoft.com/” & _
“cdo/configuration/sendusing”) = 2
oEmail.Configuration.Fields.Item (“http://schemas.microsoft.com/” & _
“cdo/configuration/smtpserver”) = mSMTPServer
oEmail.Configuration.Fields.Item (“http://schemas.microsoft.com/” & _
“cdo/configuration/smtpserverport”) = mSMTPport
oEmail.Configuration.Fields.Update
‘ Sending email
oEmail.Send

In order to send an email you need to edit the send.vbs script with your data.

You can use Windows Task Scheduler to create and manage emailing tasks that your computer will carry out automatically at the times you specify.

Leave a Reply