Sending mail with MIME, "message" parameter expected as file (?)
See original GitHub issueI tried to send message as MIME, I fall to this (with MIME) because I’m looking for sending inline attachment (from base64, file attachment is work), but all over the tutorial (included in this repository) are talking about mailgun-js, not mailgun.js.
So, here is my issue, I got this error message:
[Error: BAD REQUEST] { status: 400, details: {\n "message": "'message' parameter is not a file"\n} }
This is my code:
const formData = require('form-data');
const Mailgun = require('mailgun.js');
const mailgun = new Mailgun(formData);
const mg = mailgun.client({ username: 'api', key: data.mailgun_key });
let mail_data = {
html: data.message.html
};
if (data.message.attachments) {
mail_data.attachment = [];
mail_data.inline = [];
data.message.attachments.forEach(attachment => {
if (attachment.disposition == 'inline') {
mail_data.attachment.push({
filename: attachment.filename,
path: Buffer.from(attachment.content, 'base64'),
cid: 'logo.png'
})
}
});
}
if (data.message.bcc) {
// mail_data.bcc = data.message.bcc
}
const mail = new MailComposer(mail_data); // converting to MIME
mail.compile().build()
.then(message=>{
console.log(message)
return mg.messages.create(data.outbound_host, {
from: data.message.from_name+" <"+data.message.from_email+">",
to: data.message.to,
subject: data.message.subject,
message: message,
'h:Content-type': 'multipart/form-data'
})
})
.then(resp=>console.log('Message [%s]: %s', resp.id, resp.message))
.catch(error => {
console.log(error);
});
I’ve tried to make MIME message to string (ascii), but it still asking for a file. I dunno where should looking for answer anymore, no one talking about mailgun.js
.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Sending mail with MIME, "message" parameter expected as ...
I tried to send message as MIME, I fall to this (with MIME) because I'm looking for sending inline attachment (from base64, file...
Read more >The Message Content-Type in MIME
It is frequently desirable, in sending mail, to encapsulate another mail message. For this common operation, a special Content-Type, "message", is defined.
Read more >Sending an email via the Python email library throws error ...
Calling email() produces the error expected string or bytes-like object . Redefining server.sendmail("test@gmail.com", "testee@gmail.com", msg) ...
Read more >Seeing errors when sending a mail with files attached ... - Drupal
When sending an email with a pdf attachment you get the following errors: Warning: realpath() expects parameter 1 to be a valid path,...
Read more >MIME types (IANA media types) - HTTP - MDN Web Docs
MIME types are case-insensitive but are traditionally written in lowercase. The parameter values can be case-sensitive.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Mailcomposer is submoduled to Nodemailer (check it). About
my-file.pdf
, that is another way to send an email, but inline image need aContent-ID
so it could be a reference in html code.Alternative I found another solution, by using Nodemailer with nodemailer-mailgun-transport, there’s an example about how to send an html mail with inline image, but I though it’s not as complex as
mailgun.js
that have domain, event, stat, etc. (idk, right now I just need to send email).@TheArKaID @spijs It was a bug with handling mime messages in SDK https://github.com/mailgun/mailgun.js/pull/213 I published a fix a minute ago. Starting version 4.0.1. sending mime messages should work well.
This is an example of sending a mime message from Node.js
I used MailComposer to convert the message data object to a mime message but you may choose any other library to do that.
To send mime message from the browser you need to wrap a mime message in the blob in the next way:
where compiledMessage is a message already in mime format.