Work with RTF and Word

We often send emails with RTF and Word document as attachments by EASendMail. We can use AddAttachment method to attach RTF and Word document to message very easily. But here we will discuss how to convert RTF or Word document to html file and send the html email to end users without attachments.

First of all, we need to use Word Object(Please make sure Microsoft Word is installed on your machine) to convert the RTF or Doc to html file, secondly we can use ImportMailEx method to import html and embedded pictures to the message. The following vbscript demonstrates how to convert *.rtf to html and send message out.

Const ConnectNormal = 0
Const ConnectSSLAuto = 1
Const ConnectSTARTTLS = 2
Const ConnectDirectSSL = 3
Const ConnectTryTLS = 4

On Error Resume Next

Dim oWordApp, oWordDocuments, oWordDoc, oConverters, oConverter
Dim source, target
source = "c:\document.rtf"
target = "c:\document.htm"

Set oWordApp = CreateObject("Word.Application")
If Err.Number <> 0 Then
	WScript.Echo Err.Description
End If

oWordApp.Visible = False
Set oWordDocuments = oWordApp.Documents

Const wdFormatHTML = 8

Set oWordDoc = oWordDocuments.Open( source )
If Err.Number <> 0 Then
	WScript.Echo Err.Description
End If

oWordDoc.SaveAs target, wdFormatHTML     


If Err.Number <> 0 Then
	WScript.Echo Err.Description
End If

Dim oSmtp
Set oSmtp = CreateObject("EASendMailObj.Mail")

' for evaluation usage, please use "TryIt" as the license code.
oSmtp.LicenseCode = "TryIt"

oSmtp.ServerAddr = "myserver"

' User and password for ESMTP authentication
oSmtp.UserName = ""
oSmtp.Password = "test"

' ConnectTryTLS means if server supports SSL/TLS connection, SSL/TLS is used automatically
oSmtp.ConnectType = ConnectTryTLS

' If your server uses 587 port 
' oSmtp.ServerPort = 587

' If your server uses 465 port with SSL/TLS 
' oSmtp.ConnectType = ConnectSSLAuto 
' oSmtp.ServerPort = 465

' If your server uses 25/587 port with SSL/TLS 
' oSmtp.ConnectType = ConnectSSLAuto 
' oSmtp.ServerPort = 587

oSmtp.FromAddr = ""
oSmtp.AddRecipient "tester", "", 0

oSmtp.Subject = "Test"
oSmtp.BodyFormat = 1
If oSmtp.ImportMailEx(target) <> 0 Then
	WScript.Echo "import mail failed" 
End If

If oSmtp.SendMail() <> 0 Then
	WScript.Echo oSmtp.GetLastErrDescription()
	WScript.Echo "Message delivered"
End If

Note*: if you use Word Object in ASP/ASP.NET application, there are some issues with it, more detail, please refer to

See Also

Using EASendMail ActiveX Object
Registration-free COM with Manifest File
User Authentication and SSL Connection
From, ReplyTo, Sender and Return-Path
Digital Signature and Email Encryption - S/MIME
DomainKeys Signature and DKIM Signature
Send Email without SMTP server(DNS lookup)
Work with EASendMail Service(Mail Queuing)
Programming with Asynchronous Mode
Programming with FastSender
Mail vs. FastSender
Bulk Email Sender Guidelines
Process Bounced Email (Non-Delivery Report) and Email Tracking
EASendMail ActiveX Object References
EASendMail SMTP Component Samples