PDA

View Full Version : MIME and smtp



DmitryNik
14th September 2011, 18:46
Hello!

I have read some threads on this forum related to smtp and attachments and I've read rfc's related to MIME, but still I have a problem. I believe it's only because of my misunderstanding.

I tried to send the message with html-body and the picture. But as a result I can send either message or picture.
Here is the code related to the mail body:

"MIME-Version: 1.0\r\n"
"Content-Type: multipart/mixed\r\n"
"Received: from support@support.com\r\n"
"Date: " + date.toString() + "\r\n"
"From: Dude\r\n"
"To: Dude\r\n"
"Subject: Your PC is infected by our company\r\n"
"Content-Type: text/html; charset=UNICODE-1-1-UTF-7\r\n"
"<h1>Hello, dude!!!ääääää</h1>"
"Content-Type: image/jpg; name=pic.jpg\r\n"
"Content-Transfer-Encoding: base64\r\n" +
str +
"\r\n.\r\n"

str is base64-encoded string.

I know about boundaries, but here is another problem: MIME didn't process them, and I saw in the message something like: --_________boundary-uniq-1;
What am I doing wrong? How it can be changed?

Thank you for answers beforehand.

ChrisW67
14th September 2011, 23:44
You should specify a boundary on line 2 and use it before each part of the message. Each part of the message should specify a content type, and possible other header, and a blank line (missing above) before the actual content. See http://en.wikipedia.org/wiki/MIME#Multipart_messages for a simple example.

DmitryNik
15th September 2011, 05:30
Thank you!

If someone has the same problem, here is the code:



"Received: from support@microsoft.com\r\n"
"Date: " + date.toString() + "\r\n"
"From: Dude\r\n"
"To: Dude\r\n"
"Subject: Your PC is infected by our company\r\n"
"MIME-Version: 1.0\r\n"
"Content-Type: multipart/related; boundary=_markeraaaaa\r\n"
"\r\n"
"--_markeraaaaa\r\n"
"Content-Type: text/html; charset=UNICODE-1-1-UTF-7\r\n"
"\r\n"
"<h1>Hello, dude!!!ääääää</h1>\r\n"
"--_markeraaaaa\r\n"
"Content-Type: image/jpeg; name=pic.jpg\r\n"
"Content-Transfer-Encoding: base64\r\n"
"\r\n" +
str + "\r\n" +
"--_markeraaaaa--\r\n"
"\r\n.\r\n"



By the message, which is written above we will send one line of text and the picture. str is that picture, which was base64-encoded. For instance, in this way:


QFile file("E:\\linux-penguin-computing.jpg");
file.open(QIODevice::ReadOnly);
QString str = file.readAll().toBase64() + "\r\n";
file.close();