question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues sending an email with an image in the body

See original GitHub issue

Hello,

I want to send an email with an image in the body. I can’t seem to find any documentation on how to accomplish this. If there is any documentation where would I find it? I tried sending both the file itself from where it is stored on my computer in the email and in a base64 format, neither have worked.

Any direction would be greatly appreciated .

Thank you!

Here is my code

function congratulationsTemplate(message){
  // This line grabs the image I have stored in an uploads folder inside my directory
 // This approach isn't working and I tried sending it in a base64 format and that isn't working either.
  var image = path.join(__dirname, "../uploads/"+message.file).toString();
  var data ={
    from:'',
    to:'',
    subject: message.title,
    html: "<h1>Hello World</h1><p>Here is an image:<br/> <img src='+image+'/></p>",
    attachment: image
  };

  mailgun.messages().send(data, function (error, body) {
    if(error) throw error;
    console.log("Message Sent!");
  });
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
captDaylightcommented, Apr 3, 2018

@ptums all of that looks good, except instead of: src="cd:mailgun_logo.png" you need src="cid:mailgun_logo.png"

Also, for anyone else coming here, the same logic works for multiple images by just putting the filenames in an array: inline: [filenameone, filenametwo]

1reaction
ptumscommented, Aug 21, 2017

Thank you! This worked. It may help to edit this example to show people trying to add an inline image what the code should look like in the html key.

For example

var filename = path.join(__dirname, '/mailgun_logo.png');
var data ={
from: ...,
to: ...,
subject: ...,
html: '<div><img src="cd:mailgun_logo.png"/><h1>Thank you for choosing Mailgun!</h1></div>';
inline:filename
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Attach files or insert pictures in Outlook email messages
It's easy to attach pictures, files, contacts, emails and many other items to your Outlook messages. Outlook keeps track of the documents you've...
Read more >
Turn images on or off in Gmail - Android - Google Support
By default, when you get an email with an image, you'll see the image automatically. Always show images If images don't load in...
Read more >
Images not displaying in an email client
Apple Mail on iPhone/iPad; Gmail on Desktop, Android, and iPhone/iPad; Outlook (Outlook for Microsoft 365, Outlook 2007 to Outlook 2019) ...
Read more >
How to Send an Attachment or Photo Through E-mail
Tips on sending attachments. Gmail; Outlook.com (formerly Hotmail). Yahoo! Apple Mail; Microsoft Outlook and Outlook Express. Mozilla ...
Read more >
Why recipients may not see images in emails
Email clients refer to these as "remote" or "external" images, and may be set to display images in: no emails; a specific email...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found