Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript: create MIME message

I have user interface to send message. User enters a subject, message body, emails to send, attaches some files. After submit I need to send message as MIME message, like this:

From: John Doe <[email protected]>
MIME-Version: 1.0
Content-Type: multipart/mixed;
        boundary="XXXXboundary text"

This is a multipart message in MIME format.

--XXXXboundary text 
Content-Type: text/plain

this is the body text

--XXXXboundary text 
Content-Type: text/plain;
Content-Disposition: attachment;
        filename="test.txt"

this is the attachment text

--XXXXboundary text--

How can I gather user entered information as MIME message? I searched to build MIME message on client side with JavaScript but no success. If attachments exist, I need to convert them base64 string, then send within MIME message. Thanks.

like image 525
Ikrom Avatar asked Oct 17 '25 10:10

Ikrom


1 Answers

I've created a javascript plugin to create MIME message in javascript. https://github.com/ikr0m/mime-js. Create mail object with necessary properties and call createMimeMessage function. It returns ready MIME message as javascript string.

var mail = {  
    "to": "[email protected], [email protected]",
    "subject": "Today is rainy",
    "fromName": "John Smith",
    "from": "[email protected]",
    "body": "Sample body text",
    "cids": [],
    "attaches" : []
}
var mimeMessage = createMimeMessage(mail);
console.log(mimeMessage);    

I hope it helps.

like image 137
Ikrom Avatar answered Oct 19 '25 00:10

Ikrom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!