React Native
React Native
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 React Native Downloads
import { BinData, Email, Http, MailMan } from '@chilkat/react-native'
async function chilkatExample() {
// 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.
const bdJpg = new BinData();
const http = new Http();
try {
await http.quickGetBdAsync('https://www.chilkatsoft.com/images/starfish.jpg', bdJpg);
} catch {
console.log(http.lastErrorText);
return;
}
const mailman = new MailMan();
// Use your SMTP server..
mailman.smtpHost = 'smtp.yourserver.com';
mailman.smtpPort = 587;
mailman.startTLS = true;
// Set the SMTP login/password
mailman.smtpUsername = 'my_login';
mailman.smtpPassword = 'my_password';
// Create an HTML email.
const email = new Email();
email.subject = 'HTML Email with Image';
email.from = 'Dave <somebody@mydomain.com>';
email.addTo('Chilkat', 'info@chilkatsoft.com');
const 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.
try {
email.addRelatedBd2(bdJpg, 'starfish.jpg');
} catch {
console.log(email.lastErrorText);
return;
}
email.saveEml('qa_output/out.eml');
// success = mailman.SendEmail(email);
// if (success == ckfalse) {
// println mailman.LastErrorText;
// return;
// }
//
// ignore = mailman.CloseSmtpConnection();
console.log('Success.');
}