React Native
React Native
Embed Image in HTML Email
Demonstrates how to create and send an HTML email with an embedded image.Chilkat React Native Downloads
import { Email, 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.
// The mailman object is used for sending and receiving email.
const mailman = new MailMan();
// Set the SMTP server.
mailman.smtpHost = 'smtp.comcast.net';
// Create a new email object
const email = new Email();
// Add an embedded image to the HTML email.
const fileOnDisk = 'images/dude2.gif';
const filePathInHtml = 'dudeAbc.gif';
// Embed the GIF image in the email.
try {
email.addRelatedFile2(fileOnDisk, filePathInHtml);
} catch {
console.log(mailman.lastErrorText);
return;
}
// The src attribute for the image tag is set to the filePathInHtml:
const htmlBody = '<html><body>Embedded Image:<br><img src="dudeAbc.gif"></body></html>';
// Set the basic email stuff: HTML body, subject, "from", "to";
email.setHtmlBody(htmlBody);
email.subject = 'React Native HTML email with an embedded image.';
email.addTo('Admin', 'admin@chilkatsoft.com');
email.from = 'Chilkat Support <support@chilkatsoft.com>';
try {
await mailman.sendEmailAsync(email);
console.log('Mail Sent!');
} catch {
console.log(mailman.lastErrorText);
}
}