Results 1 to 3 of 3
Thread: Sending email with JavaMail
- 03-02-2010, 06:05 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 16
- Rep Power
- 0
setting content in email with attachment JavaMail
I am able to send email with and without attachments...however when i send an email with an attachment i cannot set anything in the content of the email...
this is the line that with without attachment works
message.setContent("This is a test.", "text/plain");
but when i have an attachment i enable this line and it does not set that content to the email
attachFilePart.setText("This is a test from attachment");
and havent nad any succes....ANY IDEAS??
Java Code:public void send(String attachment, String to) throws Exception { Properties props = new Properties(); props.put("mail.transport.protocol", "smtp"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.quitwait", "false"); Session mailSession = Session.getDefaultInstance(props); mailSession.setDebug(true); Transport transport = mailSession.getTransport(); MimeMessage message = new MimeMessage(mailSession); message.setFrom(new InternetAddress("Snapshot Integration <snapshot@blackbrd.com.mx>")); message.setRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject("Snapshot Controller"); // message.setContent("This is a test.", "text/plain"); //ATTACHMENT MimeBodyPart attachFilePart = new MimeBodyPart(); FileDataSource fds = new FileDataSource(attachment); attachFilePart.setDataHandler(new DataHandler(fds)); attachFilePart.setFileName(fds.getName()); attachFilePart.setText("This is a test from attachment"); Multipart mp = new MimeMultipart(); mp.addBodyPart(attachFilePart); message.setContent(mp); transport.connect(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD); transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO)); transport.close();Last edited by eponcedeleon; 03-02-2010 at 08:51 PM. Reason: changing title
- 03-03-2010, 01:15 AM #2
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
Use Search on this forum
and find many examples for mail sending with/without attachments.
For any question related to mail API visit:
JavaMail API - FAQ
regards
- 03-03-2010, 07:32 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 16
- Rep Power
- 0
Similar Threads
-
sending email
By kkk in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 08-21-2009, 10:20 AM -
[SOLVED] Sending Email via UNIX
By nwboy74 in forum NetworkingReplies: 4Last Post: 03-24-2009, 11:31 PM -
Need help sending an email
By isshino in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-19-2009, 08:35 PM -
sending email without SMTP?
By java_srinivasan in forum Advanced JavaReplies: 1Last Post: 07-23-2008, 03:45 PM -
Sending mail Using JAVAMAIL
By peiceonly in forum Advanced JavaReplies: 3Last Post: 07-19-2007, 02:11 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks