DataFlex
DataFlex
Amazon SES v2: Send HTML with a plain text alternative
See more Amazon SES Examples
Send a single report notification with an HTML body and a plain text alternative. Each part conveys the same information so the recipient can read it with either kind of mail client. Use a verified sender in the sending Region and grant ses:SendEmail.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoRequest
String sRegion
Handle hoHost
Variant vSigner
Handle hoSigner
Variant vConnection
Handle hoConnection
Handle hoRest
String sSessionToken
String sResponseText
Handle hoResult
String sTemp1
Integer iTemp1
Boolean bTemp1
Move False To iSuccess
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Move False To iSuccess
// Replace the From address with your verified sender. The destination is the SES mailbox simulator.
Get Create (RefClass(cComChilkatJsonObject)) To hoRequest
If (Not(IsComObjectCreated(hoRequest))) Begin
Send CreateComObject of hoRequest
End
Get ComUpdateString Of hoRequest "FromEmailAddress" "sender+reports@example.com" To iSuccess
Get ComUpdateString Of hoRequest "Destination.ToAddresses[0]" "success@simulator.amazonses.com" To iSuccess
Get ComUpdateString Of hoRequest "Content.Simple.Subject.Data" "Weekly report: 12 orders shipped" To iSuccess
Get ComUpdateString Of hoRequest "Content.Simple.Subject.Charset" "UTF-8" To iSuccess
// SES builds a multipart/alternative message from the two body representations.
Get ComUpdateString Of hoRequest "Content.Simple.Body.Text.Charset" "UTF-8" To iSuccess
Get ComUpdateString Of hoRequest "Content.Simple.Body.Text.Data" "Weekly report: 12 orders shipped." To iSuccess
Get ComUpdateString Of hoRequest "Content.Simple.Body.Html.Charset" "UTF-8" To iSuccess
Get ComUpdateString Of hoRequest "Content.Simple.Body.Html.Data" "<h1>Weekly report</h1><p><strong>12 orders</strong> shipped.</p>" To iSuccess
// Use the same AWS Region for the identity, endpoint, and Signature Version 4.
Move "us-west-2" To sRegion
Get Create (RefClass(cComChilkatStringBuilder)) To hoHost
If (Not(IsComObjectCreated(hoHost))) Begin
Send CreateComObject of hoHost
End
Get ComAppend Of hoHost "email." To iSuccess
Get ComAppend Of hoHost sRegion To iSuccess
Get ComAppend Of hoHost ".amazonaws.com" To iSuccess
Get Create (RefClass(cComChilkatAuthAws)) To hoSigner
If (Not(IsComObjectCreated(hoSigner))) Begin
Send CreateComObject of hoSigner
End
// Supply the credentials from your application's credential provider.
Set ComAccessKey Of hoSigner To "AWS_ACCESS_KEY_ID"
Set ComSecretKey Of hoSigner To "AWS_SECRET_ACCESS_KEY"
Set ComRegion Of hoSigner To sRegion
Set ComServiceName Of hoSigner To "ses"
Get Create (RefClass(cComChilkatSocket)) To hoConnection
If (Not(IsComObjectCreated(hoConnection))) Begin
Send CreateComObject of hoConnection
End
Set ComRequireSslCertVerify Of hoConnection To True
Get ComGetAsString Of hoHost To sTemp1
Get ComConnect Of hoConnection sTemp1 443 True 10000 To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoConnection To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
Get pvComObject of hoConnection to vConnection
Get ComUseConnection Of hoRest vConnection False To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get pvComObject of hoSigner to vSigner
Get ComSetAuthAws Of hoRest vSigner To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
// For temporary AWS credentials, supply the session token from the same provider.
Move "" To sSessionToken
If (sSessionToken <> "") Begin
Get ComAddQueryParam Of hoRest "X-Amz-Security-Token" sSessionToken To iSuccess
End
Get ComAddHeader Of hoRest "Content-Type" "application/json" To iSuccess
Get ComEmit Of hoRequest To sTemp1
Get ComFullRequestString Of hoRest "POST" "/v2/email/outbound-emails" sTemp1 To sResponseText
Get ComLastMethodSuccess Of hoRest To bTemp1
If (bTemp1 <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iTemp1
If (iTemp1 <> 200) Begin
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "SES returned HTTP " iTemp1 " " sResponseText
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoResult
If (Not(IsComObjectCreated(hoResult))) Begin
Send CreateComObject of hoResult
End
Get ComLoad Of hoResult sResponseText To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoResult To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComHasMember Of hoResult "MessageId" To bTemp1
If (bTemp1 <> True) Begin
Showln "SES returned no message ID."
Procedure_Return
End
Get ComStringOf Of hoResult "MessageId" To sTemp1
Showln "SES accepted the message. Message ID: " sTemp1
End_Procedure