<< Click to Display Table of Contents >> Navigation: Samples and Tutorials > VBScript > Using AddEmail in VBScript projects |
AddEmail ActiveX can be used with any environment that supports VBScript. Windows has built-in VBScript support and can execute VBScript files that have .VBS extension. To use AddEmail ActiveX from VBScript code create SmtpMail object and send a message using SimpleSendScriptable, SimpleSendAttachmentScriptable or SendScriptable. Please use code snapshots below to get started.
Snapshot 1: simple text email.
Dim objSmtpMail, strError, numResultCode
Set objSmtpMail = CreateObject("AddEmail.SmtpMail")
objSmtpMail.SmtpServer = "mail.myserver.com"
objSmtpMail.SmtpUsername = "jsmith"
objSmtpMail.SmtpPassword = "mypassword"
numResultCode = objSmtpMail.SimpleSendScriptable("jsmith@myserver.com", "jane@someserver.com;james@someserver.com", "test", "Test message", strError)
If numResultCode = 0 Then
MsgBox "Sent successfully!"
Else
MsgBox strError
End If
Snapshot 2: text email with attachments.
Dim objSmtpMail, strError, numResultCode
Set objSmtpMail = CreateObject("AddEmail.SmtpMail")
objSmtpMail.SmtpServer = "mail.myserver.com"
objSmtpMail.SmtpUsername = "jsmith"
objSmtpMail.SmtpPassword = "mypassword"
numResultCode = objSmtpMail.SimpleSendAttachmentScriptable("jsmith@myserver.com", "jane@someserver.com;james@someserver.com", "test", "Test message", "c:\files\doc1.pdf;c:\files\doc2.pdf", strError)
If numResultCode = 0 Then
MsgBox "Sent successfully!"
Else
MsgBox strError
End If
Snapshot 3: HTML message with attachments.
Dim objSmtpMail, objMailMessage, objMailAttachment, objMailAddress, strError, numResultCode
Set objSmtpMail = CreateObject("AddEmail.SmtpMail")
objSmtpMail.SmtpServer = "mail.myserver.com"
objSmtpMail.SmtpUsername = "jsmith"
objSmtpMail.SmtpPassword = "mypassword"
' Create message and setup subject and body
Set objMailMessage = CreateObject("AddEmail.MailMessage")
objMailMessage.MessageBodyFormat = 1 'HTML format
objMailMessage.MessageSubject = "test"
objMailMessage.MessageBody = "<html><body><b>Testing...</b></body></html>"
' Add first attachment
Set objMailAttachment = CreateObject("AddEmail.MailAttachment")
objMailAttachment.File = "c:\files\doc1.pdf"
objMailMessage.AddAttachment(objMailAttachment)
' Add second attachment
Set objMailAttachment = CreateObject("AddEmail.MailAttachment")
objMailAttachment.File = "c:\files\doc2.pdf"
objMailMessage.AddAttachment(objMailAttachment)
' Setup sender
Set objMailAddress = CreateObject("AddEmail.MailAddress")
objMailAddress.Name = "John Smith"
objMailAddress.Address = "jsmith@myserver.com"
objMailMessage.Sender = objMailAddress
' Setup first recipient
Set objMailAddress = CreateObject("AddEmail.MailAddress")
objMailAddress.Name = "Jane Smith"
objMailAddress.Address = "jane@someserver.com"
objMailMessage.AddRecipient(objMailAddress)
' Setup second recipient
Set objMailAddress = CreateObject("AddEmail.MailAddress")
objMailAddress.Name = "James Smith"
objMailAddress.Address = "james@someserver.com"
objMailMessage.AddRecipient(objMailAddress)
' Send prepared message
numResultCode = objSmtpMail.SendScriptable(objMailMessage, True, strError)
If numResultCode = 0 Then
MsgBox "Sent successfully!"
Else
MsgBox strError
End If
Please refer to the Reference section of this manual for detailed description of AddEmail objects, methods and properties. Included VBScript samples provide code snapshots for common operations such as sending text e-mails, sending HTML e-mails, adding attachments to e-mails.