aliaspooryorik
aliaspooryorik
<img src=cid:>
to workPatrick
07/06/2023, 3:46 PMPatrick
07/06/2023, 3:47 PM<cfscript>
// Base64-encoded image
var base64Image = "base64-encoded-image-data";
// Destination email address
var toEmail = "<mailto:recipient@example.com|recipient@example.com>";
// Sender email address
var fromEmail = "<mailto:sender@example.com|sender@example.com>";
// AWS SES configuration
var awsAccessKey = "your-aws-access-key";
var awsSecretKey = "your-aws-secret-key";
var awsRegion = "your-aws-region";
// Set AWS SDK configuration
aws = createObject("java", "com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient");
credentials = createObject("java", "com.amazonaws.auth.BasicAWSCredentials").init(awsAccessKey, awsSecretKey);
aws.setCredentials(credentials);
aws.setRegion(awsRegion);
// Convert base64 image to binary
binaryImage = binaryDecode(base64Image, "base64");
// Generate CID (Content-ID) for the embedded image
cid = createUUID();
// Create a temporary file path for the embedded image
embeddedImagePath = expandPath("/path/to/embedded/image.png");
// Save binary image to a file
fileWrite(embeddedImagePath, binaryImage);
// Construct the HTML email body with embedded image
htmlBody = "<h1>Email with Embedded Image</h1>";
htmlBody &= "<p>Here's an embedded image:</p>";
htmlBody &= "<img src='cid:#cid#' alt='Embedded Image'>";
// Send email with the embedded image
cfmail(
to = toEmail,
from = fromEmail,
subject = "Email with Embedded Image",
type = "html"
) {
// Set the HTML body
cfmailpart(type = "text/html") {
writeOutput(htmlBody);
}
// Attach the embedded image using Content-ID
cfmailparam(
file = embeddedImagePath,
contentid = cid,
disposition = "inline",
content = "image/png"
);
}
// Delete the temporary embedded image file
fileDelete(embeddedImagePath);
</cfscript>
aliaspooryorik
cfmail
🙂Patrick
07/06/2023, 3:48 PMaliaspooryorik
aliaspooryorik
Patrick
07/06/2023, 3:51 PMaliaspooryorik
aliaspooryorik
Patrick
07/06/2023, 3:54 PMPatrick
07/06/2023, 3:55 PMaliaspooryorik
aliaspooryorik
aliaspooryorik
Patrick
07/06/2023, 4:06 PMaliaspooryorik
Patrick
07/06/2023, 4:08 PMaliaspooryorik
aliaspooryorik
Patrick
07/06/2023, 4:10 PMaliaspooryorik
aliaspooryorik
Patrick
07/06/2023, 4:15 PMaliaspooryorik
HMAC
is a PITA. Nice win 🙂