Send email with attachment

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Send email with attachment

Postby goldy » Mon Feb 11, 2008 2:27 pm

Hi!

I am trying to send email with attachment (some jpg photo) with my application. I used the code from:
http://davanum.wordpress.com/2007/12/22 ... -via-smtp/

Than I added some aditional code so the send method looks like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public synchronized void sendMail(String recipient, String sender, String subject, String body, String attachment) throws Exception {
  3.  
  4.        
  5.  
  6.         // Create new email message and data handler
  7.  
  8.         MimeMessage message = new MimeMessage(session);
  9.  
  10.        
  11.  
  12.         // Set the recipient and sender address and date
  13.  
  14.         message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipient));
  15.  
  16.         message.setSender(new InternetAddress(sender));
  17.  
  18.         message.setSentDate(new Date());
  19.  
  20.         message.setSubject(subject);
  21.  
  22.        
  23.  
  24.         // Create two body parts
  25.  
  26.         BodyPart messageBodyPart = new MimeBodyPart();
  27.  
  28.         BodyPart attachmentBodyPart = new MimeBodyPart();
  29.  
  30.        
  31.  
  32.         // Set the content of the messageBodyPart
  33.  
  34.         DataSource ds = new ByteArrayDataSource(body.getBytes(), "text/plain");
  35.  
  36.         messageBodyPart.setDataHandler(new DataHandler(ds));
  37.  
  38.        
  39.  
  40.        
  41.  
  42.         // Insert the file to the attachmentBodyPart
  43.  
  44.         FileDataSource fds = new FileDataSource(new File("/data/data/com.google.android.photo/files/photo.jpg"));
  45.  
  46.         attachmentBodyPart.setDataHandler(new DataHandler(fds));
  47.  
  48.         attachmentBodyPart.setHeader("image/jpeg", "<image>");
  49.  
  50.         attachmentBodyPart.setFileName("photo.jpg");
  51.  
  52.         attachmentBodyPart.setDisposition(Part.ATTACHMENT);
  53.  
  54.  
  55.  
  56.         // Create a related multi-part to combine the parts
  57.  
  58.         MimeMultipart multipart = new MimeMultipart("alternative");
  59.  
  60.        
  61.  
  62.         // Add body parts to multipart
  63.  
  64.         multipart.addBodyPart(messageBodyPart);
  65.  
  66.         multipart.addBodyPart(attachmentBodyPart);
  67.  
  68.        
  69.  
  70.         // Associate multipart with message
  71.  
  72.         message.setContent(multipart);
  73.  
  74.         message.saveChanges();
  75.  
  76.              
  77.  
  78.         // Send the message
  79.  
  80.         Transport.send(message);
  81.  
  82. }
  83.  
  84.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


The file photo.jpg is captured with emulator and saved to specified path. The compiler and emulator give me no errors when executing the code but I get no email in may email inbox either.

I think that there is a problem in formation of email message but I don't know where.. Can anybody show me what am I doing wrong. Where is the problem?

Thanks!
Regards, Goldy
goldy
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Feb 11, 2008 1:03 pm
Location: Slovenia

Top

Postby DeveloperAmit » Wed Mar 04, 2009 3:46 pm

Last edited by DeveloperAmit on Thu Mar 05, 2009 2:47 pm, edited 1 time in total.
DeveloperAmit
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Mar 04, 2009 1:26 pm

Postby galert » Wed Mar 04, 2009 7:41 pm

can u post the entire code for yr email attachment application...the send email via smtp link doesnt work anymore...
Thanks in advance!
galert
Freshman
Freshman
 
Posts: 4
Joined: Wed Feb 18, 2009 6:57 pm

Postby galert » Wed Mar 04, 2009 9:58 pm

can someone telme how to send an image from one emulator to the other via MMS/email or anything else?????
galert
Freshman
Freshman
 
Posts: 4
Joined: Wed Feb 18, 2009 6:57 pm

Postby DeveloperAmit » Thu Mar 05, 2009 6:36 am

Thats the entire code for email my friend...
DeveloperAmit
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Mar 04, 2009 1:26 pm

Postby download9719 » Fri Mar 27, 2009 3:58 am

DeveloperAmit wrote:Thats the entire code for email my friend...

It means that when you use the code from:
http://davanum.wordpress.com/2007/12/22 ... -via-smtp/
you can emulator it rightly?

I am meeting the trouble in DataHandler, can you help me? :(
Maybe I have mistake at java.awt.datatransfer (I have already added activation-1.1.jar, mail-1.4.jar into my apply). I dont understand which classes are necessary as well as how to add them into my apply
I will be very happy if you share your apply with me
My mail address is : ntsonca@gmail.com
download9719
Freshman
Freshman
 
Posts: 3
Joined: Tue Jan 27, 2009 1:23 pm

Top

Postby download9719 » Fri Mar 27, 2009 8:30 am

I also have the problem [ java.lang.VerifyError: javax.mail.internet.MineMessage]
Maybe activation-1.1.jar, mail-1.4.jar have error.
Pls help me.
Thanks alot
download9719
Freshman
Freshman
 
Posts: 3
Joined: Tue Jan 27, 2009 1:23 pm

Postby llanero » Sat Apr 04, 2009 3:31 pm

Hi,
I'm in the same point of you and need also help to continue. This problem must to be a big problem! :? :?
thanks.
llanero
Freshman
Freshman
 
Posts: 2
Joined: Thu Apr 02, 2009 10:45 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 4 guests