Xbase++
Xbase++
Send HTML Email with Image to iPhone
Demonstrates how to compose an HTML email with an embedded image that will display correctly on an iPhone. This example produces an email that looks like this on the iPhone:
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oMailman
LOCAL oEmail
LOCAL cContentIdStarfish
LOCAL oSbHtml
LOCAL nNumReplacements
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The mailman object is used for sending and receiving email.
oMailman := CreateObject("Chilkat.MailMan")
// Use your SMTP server hostname. This example uses office365, but it could be any SMTP server..
oMailman:SmtpHost := "outlook.office365.com"
oMailman:SmtpPort := 587
oMailman:StartTLS := 1
// Set the SMTP login/password
oMailman:SmtpUsername := "OFFICE365-SMTP-LOGIN"
oMailman:SmtpPassword := "OFFICE365-SMTP-PASSWORD"
// Create a new email object
oEmail := CreateObject("Chilkat.Email")
oEmail:Subject := "Testing for Chilkat SMTP API..."
oEmail:Body := "Testing for Chilkat SMTP API..."
oEmail:From := "Chilkat Support <my-office365-user@mydomain.com>"
oEmail:AddTo("Chilkat Support", "support@chilkatsoft.com")
// For whatever reason, the iPhone's email program requires
// images in HTML to be referenced by Content-ID. Therefore,
// we must add the image like this:
cContentIdStarfish := oEmail:AddRelatedFile("qa_data/jpg/starfish.jpg")
IF (oEmail:LastMethodSuccess != 1)
? oEmail:LastErrorText
oMailman:destroy()
oEmail:destroy()
RETURN
ENDIF
// The src attribute for the image tag is set to the contentIdStarfish:
oSbHtml := CreateObject("Chilkat.StringBuilder")
oSbHtml:Append("<html><body><p>This is an HTML email with an embedded image.</p>")
oSbHtml:Append('<p><img src="cid:CONTENT_ID_STARFISH" /></p></body></html>')
nNumReplacements := oSbHtml:Replace("CONTENT_ID_STARFISH", cContentIdStarfish)
oEmail:SetHtmlBody(oSbHtml:GetAsString())
nSuccess := oMailman:SendEmail(oEmail)
IF (nSuccess != 1)
? oMailman:LastErrorText
ELSE
? "Mail Sent!"
ENDIF
oMailman:destroy()
oEmail:destroy()
oSbHtml:destroy()