PowerBuilder
PowerBuilder
Add File Attachments to an Email
Demonstrates how to add one or more file attachments to an email.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Email
string ls_ContentType
li_Success = 0
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
destroy loo_Email
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Email.Subject = "This is a test"
loo_Email.Body = "This is a test"
loo_Email.From = "support@chilkatsoft.com"
li_Success = loo_Email.AddTo("Chilkat Admin","admin@chilkatsoft.com")
// To add file attachments to an email, call AddFileAttachment
// once for each file to be attached. The method returns
// the content-type of the attachment if successful, otherwise
// returns cknull
ls_ContentType = loo_Email.AddFileAttachment("something.pdf")
if loo_Email.LastMethodSuccess <> 1 then
Write-Debug loo_Email.LastErrorText
destroy loo_Email
return
end if
ls_ContentType = loo_Email.AddFileAttachment("something.xml")
if loo_Email.LastMethodSuccess <> 1 then
Write-Debug loo_Email.LastErrorText
destroy loo_Email
return
end if
ls_ContentType = loo_Email.AddFileAttachment("something.zip")
if loo_Email.LastMethodSuccess <> 1 then
Write-Debug loo_Email.LastErrorText
destroy loo_Email
return
end if
li_Success = loo_Email.SaveEml("email.eml")
if li_Success = 0 then
Write-Debug loo_Email.LastErrorText
destroy loo_Email
return
end if
Write-Debug "Saved EML!"
destroy loo_Email