Sending email with file attachments


do you know if there is a way of sending emails via smtp with file attachments included? does ofxMailUtils do this?


ok i got it working via this excellent opensource lib jwSMTP

btw did you ever try Poco’s built in mail sending?
Its meant to be able to SMTP.

Either way a simple wrapper for either would be super awesome - great for long term installations.

btw did you ever try Poco’s built in mail sending?

ofxMailUtil does just that : )

doesn’t support attachments unless you encode them manually in the content but it should be easy to add that feature.

oh super nice, how did I miss that - yes attachments would be a great addition!

hmm… any updates on supporting email attachments?

We’re getting ready to roll up our sleeves on building apps that send emails with attachments…

don’t have very much time to modify it, but it should be easy…

in ofxMailUtils the content is set in the poco mail message by calling setContent. that makes the message a 1 part only. it seems that by using addContent / addAttachment you can create a multipart message. usually files sent as attachments are encoded as base64, can’t guess from the documentation if the function automatically does that or you need to encode the files before

the docs for the mailmessage are in:…-ssage.html

when calling addAttachment you need to create a sourcepart, you can create a filepart:…-ource.html

or from a string…-ource.html

if it needs encoding, i think the way to go is to create a std filestream and use writeEncoded in mailmessage to encode that to an ostream, convert that to a string and then use stringpartsource to create the attachment from the encoded string

I was also wondering if there is any support for SSL or TLS?

I was hoping to talk to gmail with it, but they require SSL for POP3 and SSL or TLS for SMTP.

Those look like some great resources arturo, thanks!

I will hopefully getting into this sometime this week!


ok… got attachments working with the ofxMailUtils… it was actually really easy.

I added to struct ofxMailMessage, a vector attachments;

and in the ofxMailMessage::getPocoMessage method, added:

		for(unsigned int i=0; i < attachments.size(); i++){  
			message.addAttachment(attachments[i], new Poco::Net::FilePartSource(ofToDataPath(attachments[i], true)));  

I’m still wondering about the SSL/TSL support though. If I could figure out how to recompile the poco library to include the SSL module, I could try tackling that as well.

ok… found a small bug that my message content wasn’t getting sent when I had an attachment. And when there wasn’t an attachment and I didn’t set my message contentType to text/html, the message content was being received as an attachment instead of as the actual message body (in gmail at least).

The solution is simple enough:

in the ofxMailMessage::getPocoMessage() method…


message.addContent(new Poco::Net::StringPartSource(content));

and everything works beautifully!

hey thanks for that!

just uploaded that changes to github, only i named the variable attachmentPaths in case there’s a way of adding contents from memory.

about the SSL thing, sorry for late reply, i remembered it wasn’t the standard way of compiling static but couldn’t remember how. anyway has just been taking a look you need to:


then edit build/config/Darwin

replace the line

with the line


and then:

make -s

oh, rad. thanks Arturo! I will look into compiling and implementing that tomorrow. Maybe soon we will be able to check gmail from within openFrameworks! hehe can’t wait to make some weird email viz. :stuck_out_tongue:

I am working on a media installation where museum visitors will send animated gifs as email attachments. The ofxMailUtils addon seems to work really well except that we are having trouble closing the files stream.

We used the latest version with vector attachments and this works like a charm the first time. The problem is the file cannot be overwritten once attached (still being used by our application). In an installation like this it will turn into a real problem after eight hours.

It must be related to FilePartSource but we are having some issues getting a handle on this. Does anyone have any ideas or alternate approaches?

Really appreciated!

Hey there, I just pushed a new addon called ofxSMTP. It supports attachments, and loads of other features. It’s pure poco and supports GMAIL, STARTTLS, SSL/TLS, etc etc.

Check it out.

Hi, everyone!
I’m trying to use MailUtils in my oF074 project and it fails as ofxThread is deprecated in 0.7.4
What’s the proper way to use ofThread instead of ofxThread?

Hi Christopher, thanx for you work, but I can’t get the examples ofxSMTP to work… It uses the add-on ofxCrytoUtils that isn’t included, nor can be found on the web… I must be missing something here… any help?

Hi @StudioBeneden - can you make sure you have the latest update from here:

The only additional addons you should need are ofxSSLManager and ofxXmlSettings (in the core).

Thank you for your quick response. I don’t know which branch or version I downloaded from github in the fist place, probably followed some ancient google link… With the latest version and the right addons it works :slight_smile:

1 Like

Hi ! thanx for your work but I met troubles when I loaded ofxSMTP into Xcode(0.8.4). I said cannot find file “fox/SMTP/Credentials.h” and “GmailSettings.h”. I downloaded the latest version from your github with ofxSSLManager. Very confused about it … Could you please help me? Thank you!