Using AddEmail in PowerBuilder projects
Previous  Top  Next


AddEmail ActiveX can be used to send emails from PowerBuilder applications. To use AddEmail in your PowerBuilder project you need to add a code that creates SmtpMail object and sends a message using SimpleSend, SimpleSendAttachment or Send. Please use code snapshots below to get started.


Snapshot 1: simple text email.

OLEObject
 objSmtpMail
string
 strError
long
 numResultCode
 
objSmtpMail = Create
 OLEObject
If
 objSmtpMail.ConnectToNewObject("AddEmail.SmtpMail") < 0 Then
        Destroy
 objSmtpMail
        MessageBox("AddEmail", "Can't create AddEmail.SmtpMail COM object")
        Return

End If


objSmtpMail.SmtpServer = "mail.myserver.com"
objSmtpMail.SmtpUsername = "jsmith"
objSmtpMail.SmtpPassword = "mypassword"
numResultCode = objSmtpMail.SimpleSend("jsmith@myserver.com", "jane@someserver.com;james@someserver.com", "test", "Test message", Ref strError)
If
 numResultCode = 0 Then
    MessageBox("AddEmail", "Sent successfully!")
Else

    MessageBox("AddEmail", strError)
End If

Destroy
 objSmtpMail


Snapshot 2: text email with attachments.

OLEObject
 objSmtpMail
string
 strError
long
 numResultCode
 
objSmtpMail = Create
 OLEObject
If
 objSmtpMail.ConnectToNewObject("AddEmail.SmtpMail") < 0 Then
        Destroy
 objSmtpMail
        MessageBox("AddEmail", "Can't create AddEmail.SmtpMail COM object")
        Return

End If


objSmtpMail.SmtpServer = "mail.myserver.com"
objSmtpMail.SmtpUsername = "jsmith"
objSmtpMail.SmtpPassword = "mypassword"
numResultCode = objSmtpMail.SimpleSendAttachment("jsmith@myserver.com", "jane@someserver.com;james@someserver.com", "test", "Test message", "c:\files\doc1.pdf;c:\files\doc2.pdf", Ref strError)
If
 numResultCode = 0 Then
    MessageBox("AddEmail", "Sent successfully!")
Else

    MessageBox("AddEmail", strError)
End If

Destroy
 objSmtpMail


Snapshot 2: HTML message with attachments.

OLEObject
 objSmtpMail, objMailMessage, objMailAttachment, objMailAddress
string
 strError
long
 numResultCode
 
objSmtpMail = Create OLEObject

If
 objSmtpMail.ConnectToNewObject("AddEmail.SmtpMail") < 0 Then         
        Destroy
 objSmtpMail
        MessageBox("AddEmail", "Can't create AddEmail.SmtpMail COM object")
        Return

End If
  
objSmtpMail.SmtpServer = "mail.myserver.com"
objSmtpMail.SmtpUsername = "jsmith"
objSmtpMail.SmtpPassword = "mypassword"
 
objMailMessage = Create OLEObject

objMailMessage.ConnectToNewObject("AddEmail.MailMessage")
objMailMessage.MessageBodyFormat = 1
objMailMessage.MessageSubject = "test"
objMailMessage.MessageBody = "<html><body><b>Testing...</b></body></html>"
 
objMailAttachment = Create OLEObject

objMailAttachment.ConnectToNewObject("AddEmail.MailAttachment")
objMailAttachment.File = "c:\files\doc1.pdf"
objMailMessage.AddAttachment(objMailAttachment)
 
objMailAttachment = Create OLEObject

objMailAttachment.ConnectToNewObject("AddEmail.MailAttachment")
objMailAttachment.File = "c:\files\doc2.pdf"
objMailMessage.AddAttachment(objMailAttachment)
 
objMailAddress = Create OLEObject

objMailAddress.ConnectToNewObject("AddEmail.MailAddress")
objMailAddress.Name = "John Smith" 
objMailAddress.Address = "jsmith@myserver.com" 
objMailMessage.Sender = objMailAddress
 
objMailAddress.ConnectToNewObject("AddEmail.MailAddress")
objMailAddress.Name = "Jane Smith"
objMailAddress.Address = "jane@someserver.com"
objMailMessage.AddRecipient(objMailAddress)
 
objMailAddress.ConnectToNewObject("AddEmail.MailAddress")
objMailAddress.Name = "James Smith" 
objMailAddress.Address = "james@someserver.com" 
objMailMessage.AddRecipient(objMailAddress)
 
numResultCode = objSmtpMail.Send(objMailMessage, True, Ref strError)
If
 numResultCode = 0 Then
    MessageBox("AddEmail", "Sent successfully!")
Else

    MessageBox("AddEmail", strError)
End If

Destroy
 objSmtpMail
Destroy
 objMailMessage
Destroy
 objMailAddress
Destroy
 objMailAttachment


Please refer to the Reference section of this manual for detailed description of AddEmail objects, methods and properties.