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.

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")

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

oSmtp.ServerAddr = "myserver"

'If your server require user authentication
'oSmtp.UserName = ""
'oSmtp.Password = "test"

'If your server requires SSL connection
'oSmtp.SSL_starttls = 0
'oSmtp.ServerPort = 465

''If your server requires TLS connection
'oSmtp.SSL_starttls = 1
'oSmtp.ServerPort = 25

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