Go
Go
Send HTML Email with Image Downloaded from URL
Demonstrates how to compose an HTML email with an embedded image where the image data is downloaded from a URL.Chilkat Go Downloads
success := false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// First download the image we'll be adding to the HTML "img" tag.
bdJpg := chilkat.NewBinData()
http := chilkat.NewHttp()
success = http.QuickGetBd("https://www.chilkatsoft.com/images/starfish.jpg",bdJpg)
if success == false {
fmt.Println(http.LastErrorText())
bdJpg.DisposeBinData()
http.DisposeHttp()
return
}
mailman := chilkat.NewMailMan()
// Use your SMTP server..
mailman.SetSmtpHost("smtp.yourserver.com")
mailman.SetSmtpPort(587)
mailman.SetStartTLS(true)
// Set the SMTP login/password
mailman.SetSmtpUsername("my_login")
mailman.SetSmtpPassword("my_password")
// Create an HTML email.
email := chilkat.NewEmail()
email.SetSubject("HTML Email with Image")
email.SetFrom("Dave <somebody@mydomain.com>")
email.AddTo("Chilkat","info@chilkatsoft.com")
html := "<html><body><p>This is an HTML email with an embedded image.</p><p><img src=\"starfish.jpg\" /></p></body></html>"
email.SetHtmlBody(html)
// Note: The "starfish.jpg" here must match the name in the "img" tag's "src" attribute in the HTML above.
success = email.AddRelatedBd2(bdJpg,"starfish.jpg")
if success == false {
fmt.Println(email.LastErrorText())
bdJpg.DisposeBinData()
http.DisposeHttp()
mailman.DisposeMailMan()
email.DisposeEmail()
return
}
email.SaveEml("qa_output/out.eml")
// success = mailman.SendEmail(email);
// if (success == ckfalse) {
// println mailman.LastErrorText;
// return;
// }
//
// ignore = mailman.CloseSmtpConnection();
fmt.Println("Success.")
bdJpg.DisposeBinData()
http.DisposeHttp()
mailman.DisposeMailMan()
email.DisposeEmail()