How to send an email with attachment

798 views
Skip to first unread message

Bayarmunkh Davaadorj

unread,
Jun 8, 2011, 12:21:46 PM6/8/11
to lif...@googlegroups.com
Hi,

I am using net.liftweb.util.Mailer to send an email. I am just wondering how to send an email with attachment. Does anyone know?

Thanks,
Valery

TylerWeir

unread,
Jun 8, 2011, 12:54:56 PM6/8/11
to lif...@googlegroups.com
Mailer uses javax.mail

So any example regarding sending attachments you see using javax.mail will work with Mailer.

You'll just need to translate the java to scala.

Bayarmunkh Davaadorj

unread,
Jun 8, 2011, 3:09:11 PM6/8/11
to lif...@googlegroups.com
Much appreciate for help. Thanks

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To view this discussion on the web visit https://groups.google.com/d/msg/liftweb/-/YzltMkJfSTdfRWNK.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.



--
Regards,
Bayarmunkh
chi...@gmail.com

Cell Phone: 641/233-0537

Naftoli Gugenheim

unread,
Jun 15, 2011, 10:14:28 PM6/15/11
to lif...@googlegroups.com
Here's some code of mine that attaches a vCard:

import net.liftweb.util.Mailer
  import Mailer._

object Util extends net.liftweb.common.Logger {
  def emailVCard(subject: String, to: String, body: xml.NodeSeq, card: String) {
     val attachment = PlusImageHolder("vcard.vcf", "text/x-vcard", card.getBytes)
     val email = XHTMLPlusImages(body, attachment)
     sendMail(From("xx...@xxxx.xxxxxx.org"), Subject(subject), To(to), email)
  }
  // ...
}

Incidentally some BlackBerrys recently stopped recognizing it, not sure why.

In any case you're creating a PlusImageHolder with a filename, mime type, and Array[Byte].



--
You received this message because you are subscribed to the Google Groups "Lift" group.

Viktor Hedefalk

unread,
Feb 10, 2012, 8:56:43 AM2/10/12
to lif...@googlegroups.com
I'm having problems with sending attachments from my app. I haven't been able to catch this problem until now when I have a lot of Microsoft-users receiving mail from my app 

There is a bug in some version of Exchange that causes my PDF attachments to not show [1]. It seems to also be a problem with iPhones using Google accounts… (they use the Exchange-protocol, no?) I found this blog entry about it [2].

The bug manifests itself simply by not showing any attachments in the mail. For Microsoft users I have been able to tell them to use the web interface (OWA) and since they see the attachment there they kind of realize it's their software that's causing the problem and get off my back. It's still bad though, and I would really like to fix it.

Has anybody had this problem? I would guess the BlackBerrys Naftoli mentions is probably the same thing?

Is there an alternative way to embed the attachments that circumvents this bug?

Any help is highly appreciated.


Viktor Hedefalk

unread,
Feb 10, 2012, 9:11:36 AM2/10/12
to lif...@googlegroups.com
I don't have the patience to read too much right now, but I got the feeling that "Content-disposition: inline" is the problem. Mailer.buildMailBody uses:

 rel_bpi.setDisposition("inline")

but put's them all in the end anyways. I'm gonna try to change it to

 rel_bpi.setDisposition("attachment")

and see what happens. I'll report back.

Thanks,
Viktor


--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

Viktor Hedefalk

unread,
Feb 10, 2012, 9:49:29 AM2/10/12
to lif...@googlegroups.com
Nope, it didn't help using either "attachment" nor empty Content-Disposition…

Cheers,
Viktor

Viktor Hedefalk

unread,
Feb 10, 2012, 10:04:28 AM2/10/12
to lif...@googlegroups.com
Ok, I finally found it. It seems "multipart/related" in the surrounding Content-type that was causing my issues.

I simply changed to "mixed" instead which I understand is the default:
Mailer.buildMailBody:

val html_mp = new MimeMultipart("related")

->

val html_mp = new MimeMultipart("mixed")


and now my attachments show in iPhones. Oh yes!

Even inline attachments works now so I guess that Exchange bug wasn't really relevant.


Thanks,
Viktor

Diego Medina

unread,
Feb 10, 2012, 10:06:17 AM2/10/12
to lif...@googlegroups.com
Thanks for posting the solution!

Diego

--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com

Viktor Hedefalk

unread,
Feb 10, 2012, 10:23:06 AM2/10/12
to lif...@googlegroups.com
It didn't seem to be just Exchange that had problems showing the PDF:s. I colleague with iPhone to Gmail over iMAP experienced the problem too…


Just a further thought:

I now understand why it's called XHTMLPlusImages. I guess "multipart/related" is typically used to send a complete web page with images that can be referred too by the html [1]. So I guess that was the original use case for this part of Mailer. And I guess "related" is needed in this case. Maybe original author (dpp?) can confirm…?

However, "related" seems to break MY use case for lots of clients, so maybe we should have either a way to control this by the user of Mailer or something more than PlusImageHolder to hold other attachments like PDF:s and some smart way of deciding what header to choose.




Thanks,
Viktor

David Pollak

unread,
Feb 10, 2012, 12:19:16 PM2/10/12
to lif...@googlegroups.com
On Fri, Feb 10, 2012 at 7:23 AM, Viktor Hedefalk <hede...@gmail.com> wrote:
It didn't seem to be just Exchange that had problems showing the PDF:s. I colleague with iPhone to Gmail over iMAP experienced the problem too…


Just a further thought:

I now understand why it's called XHTMLPlusImages. I guess "multipart/related" is typically used to send a complete web page with images that can be referred too by the html [1]. So I guess that was the original use case for this part of Mailer. And I guess "related" is needed in this case. Maybe original author (dpp?) can confirm…?


I don't remember why I did it that way. :-(
 
However, "related" seems to break MY use case for lots of clients, so maybe we should have either a way to control this by the user of Mailer or something more than PlusImageHolder to hold other attachments like PDF:s and some smart way of deciding what header to choose.

Can you open a ticket with some enhancements to Mailer so we can make it better?



--
Visi.Pro, Cloud Computing for the Rest of Us http://visi.pro
Lift, the simply functional web framework http://liftweb.net


Viktor Hedefalk

unread,
Feb 10, 2012, 2:36:14 PM2/10/12
to lif...@googlegroups.com
 
I don't remember why I did it that way. :-( 

:)

Can you open a ticket with some enhancements to Mailer so we can make it better?

Franz Bettag

unread,
Feb 12, 2012, 12:55:26 PM2/12/12
to lif...@googlegroups.com
I used the native java stuff like this https://gist.github.com/1809910

Mike Limansky

unread,
Jan 23, 2013, 4:02:34 AM1/23/13
to lif...@googlegroups.com
Hi all,

  I've prepared patch for Lift 2.5 to fix the MIME structure. It composes the mail the same way as gmail and outlook for the mail with both inline images and attachments (the only difference, that Lift doesn't add plain/text alternative part). It works for me, but it would be nice if someone else will test it.

The sample code for testing is available in this gist https://gist.github.com/4603352 (you should place correct email settings before running in the code). Or you can build Lift from my github repo fork: https://github.com/limansky/framework

--
Regards,
Mike.

среда, 8 июня 2011 г., 18:21:46 UTC+2 пользователь Chka написал:
Reply all
Reply to author
Forward
0 new messages