Pages: [1]
Author Topic: sending email with file attachments  (Read 1025 times)
Chris OShea
Administrator
London

Posts: 613

Gravatar

Artist / designer / inventor


WWW
sending email with file attachments
« on: January 07, 2010, 02:28:40 PM »

hi

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

thanks
chris
Logged

Chris OShea
Administrator
London

Posts: 613

Gravatar

Artist / designer / inventor


WWW
Re: sending email with file attachments
« Reply #1 on: January 07, 2010, 11:53:48 PM »

ok i got it working via this excellent opensource lib jwSMTP
http://www.mumbleface.net/jwsmtp
Logged

theo
Administrator
Amsterdam

Posts: 1007

Gravatar


WWW
Re: sending email with file attachments
« Reply #2 on: January 08, 2010, 12:57:56 PM »

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.
Logged

arturo
Administrator
barcelona

Posts: 2214

Gravatar


WWW
Re: sending email with file attachments
« Reply #3 on: January 08, 2010, 01:37:09 PM »

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

ofxMailUtil does just that : )

http://github.com/arturoc/ofxMailUtils

doesn't support attachments unless you encode them manually in the content but it should be easy to add that feature.
Logged
theo
Administrator
Amsterdam

Posts: 1007

Gravatar


WWW
Re: sending email with file attachments
« Reply #4 on: January 08, 2010, 02:51:23 PM »

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

plong0
Vancouver, BC, Canada

Posts: 292

Gravatar


WWW
Re: sending email with file attachments
« Reply #5 on: February 15, 2010, 11:54:25 PM »

hmm... any updates on supporting email attachments?

We're getting ready to roll up our sleeves on building apps that send emails with attachments...
Logged

arturo
Administrator
barcelona

Posts: 2214

Gravatar


WWW
Re: sending email with file attachments
« Reply #6 on: February 16, 2010, 12:09:56 AM »

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:

http://www.appinf.com/docs/poco/Poco.Ne ... ssage.html

when calling addAttachment you need to create a sourcepart, you can create a filepart:

http://www.appinf.com/docs/poco/Poco.Ne ... ource.html

or from a string

http://www.appinf.com/docs/poco/Poco.Ne ... 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
Logged
plong0
Vancouver, BC, Canada

Posts: 292

Gravatar


WWW
Re: sending email with file attachments
« Reply #7 on: February 16, 2010, 12:51:24 AM »

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.
Logged

plong0
Vancouver, BC, Canada

Posts: 292

Gravatar


WWW
Re: sending email with file attachments
« Reply #8 on: February 16, 2010, 01:00:56 AM »

Those look like some great resources arturo, thanks!

I will hopefully getting into this sometime this week!

Cheers,
-Pat
Logged

plong0
Vancouver, BC, Canada

Posts: 292

Gravatar


WWW
Re: sending email with file attachments
« Reply #9 on: March 03, 2010, 09:43:27 PM »

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

I added to struct ofxMailMessage, a vector<string> attachments;

and in the ofxMailMessage::getPocoMessage method, added:
Code:
		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.
« Last Edit: March 04, 2010, 12:00:30 AM by plong0 » Logged

plong0
Vancouver, BC, Canada

Posts: 292

Gravatar


WWW
Re: sending email with file attachments
« Reply #10 on: March 03, 2010, 11:59:23 PM »

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...

change
message.setContent(content);

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

and everything works beautifully!
Logged

arturo
Administrator
barcelona

Posts: 2214

Gravatar


WWW
Re: sending email with file attachments
« Reply #11 on: March 04, 2010, 12:01:23 AM »

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:

./configure

then edit build/config/Darwin

replace the line

LINKMODE = SHARED
with the line

LINKMODE = STATIC

and then:

make -s
Logged
plong0
Vancouver, BC, Canada

Posts: 292

Gravatar


WWW
Re: sending email with file attachments
« Reply #12 on: March 04, 2010, 12:11:00 AM »

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. :P
Logged

Pages: [1]
 
Jump to:  

Powered by SMF 1.1.15 | SMF © 2011, Simple Machines
kinect

viagra priser