Blog

At the begining I thought I'll need to send text only through email. But the more I thought about it, I understood that I want to add three files to the mail as well. By altering previous code I managed to add simple Multipart MIME message support. In other words file attachments.

If you are looking how to send an e-mail from Qt please refer to this article, because here I will write an introduction in MIME data headers and how to alter a simple SMTP message to inlcude file attachments.

Update

What is MIME?

Multipurpose Internet Mail Extension (MIME) is an internet standard which improves the basic email format to support file attachments, for example audio, video, images, applications and other kind of files can be attached to the message. In addition, MIME allows formating the email in different characters sets, it's not limited to only ASCII. There are more abilities to MIME, but these were the most interesting to me.

For our extension we are going to use a special kind of MIME message with multiple parts, obsiously it's called "MIME multipart message". Let's look at a simple examples.

An email without MIME would look something like this:

To: someone@mail.com
From: me@mail.com
Subject: this is a subject
And this is the body of the message

The same message in multipart MIME with multiple files attached to it would look something like this:

You should be able to see that the MIME message consists of three parts, seperated by a keyword "frontier". The keyword can be any string you like, which you specify on this line: Content-Type:multipart/mixed;boundary=frontier. Normally it's a long random string, which will be highly unlikely to occur in the message. And finally to end the message you have to but the boundary keyword in betwwen these two characters "--", as you can see in the very last line.

For every part of the message you have to specify the content type. For the body it's always going to be text/plain, however for files it can be changed, but nowdays every attachment can be specified as application/octet-stream. As for as I know it might not be the best practice, but it works in my case. For example here could be content types like: audio/basic, application/porstscript and so on. But as I said for downloadable attachments relativly anything can be specified as application/octet-stream.

For files you can see in the sample MIME message two more properties - Content-Disposition and Content-Transfer-Encoding.

Basically by adding Content-Disposition: attachment; filename=simplefile1.txt; it specifies that this part should be viewed as a downloadable file instead of viewing directly in the body of the message. Typically if a web broser will find this property, it will prompt the user to save the contents of the page, instead of showing it inline with email.

The Content-Transfer-Encoding is a MIME property to specify in what encoding the binary data will be represented other than ASCII.

A message content can be encoded with following types:

7bit

quoted-printable

base64

8bit (only if SMTP has 8BITMIME extension)

binary (only if servers support BINARYMIME extension)

Because of the integrated base64 encoding in Qt, I chose to use that. In addition, it should be supported by a standard SMTP server without any extensions. But it's just preference, you can encode your data however you like.

Basically that's all you have to know to send an email using SMTP protocol thourgh Qt5. It's all about the formating the data, the principles are the same as in my previous article.

Update (14/07/2013)

Thanks to lilgoldfish, I noticed that the message couldn't be received on most of the email clients.After some tweaking an re-reading the MIME message description, managed to found why is that. So if your message doesn't appear, HTML or plain, that means that your MIME data is incorrectly formated. Apperantly every single breakline is important. So if a MIME message has a new line between break string, then it should be there. Not all the email clients are as awesome as GMAIL. Another thing I noticed is, when you send a file with content type octet-stream gmail will be able to understand that it is a picture or a text file automatically. However that is not the case for yahoo.

When sending HTML formatted mails, be careful on your HTML formating. Because, there are spam filters, which will automatically assume your email is a spam if the HTML misses a tag or in other ways is formated sloppy.

It is great for all, I have some different tricks if you want to know it then for that I have some different tricks, for that, you want to learn to code. For that, if you want to know it then for that you just visit some tutorial. And from there it is great for all. If you faced any type...

I have read the post and it is very much helpful because I have got to know about the open cv on the raspberry pi. The images and the screenshots provided here will guide you for your questions. The code you will get here is very unique and can be only used to run OpenCV. If you face any...