Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Paul Clapham
Tim Cooke
Devaka Cooray
Sheriffs:
Liutauras Vilda
paul wheaton
Rob Spoor
Saloon Keepers:
Tim Moores
Stephan van Hulst
Tim Holloway
Piet Souris
Mikalai Zaikin
Bartenders:
Carey Brown
Roland Mueller
Forum:
Java in General
Automatic sending of email
Ådne Brunborg
Ranch Hand
Posts: 208
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
In my current project, there is a method for automatic sending of email messages. I need to expand this method to attach a file, and there is no "addAttachment" method on javax.mail.Message or javax.mail.internet.MimeMessage
public class MailSender extends Thread { //stuff public void run() { try { Properties props = new Properties(); props.put("mail.smtp.host", propertiesHelper.getProperty(PropertiesNames.GENERAL_MAIL_SERVER)); javax.mail.Session session = javax.mail.Session.getDefaultInstance(props, null); Message msg = new MimeMessage(session); //setting content, address, etc on msg Transport.send(msg); } catch (Exception ex) { logger.error(ex); } }
Entia non sunt multiplicanda praeter necessitatem
Paul Sturrock
Bartender
Posts: 10336
I like...
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Mime messages are made up of parts, so you don't add an attachement to the message, rather you create a part that is a file. For example:
BodyPart part = new MimeBodyPart(); DataSource file = new FileDataSource("file_name"); part.setDataHandler(new DataHandler(file)); part.setFileName("file_name"); multipart.addBodyPart(part);
[ November 15, 2006: Message edited by: Paul Sturrock ]
JavaRanch FAQ
HowToAskQuestionsOnJavaRanch
Ådne Brunborg
Ranch Hand
Posts: 208
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thank you
Entia non sunt multiplicanda praeter necessitatem
How do they get the deer to cross at the signs? Or to read this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Email generator
Where to find Email errors
Java Mail
Sending Email via java servlet
how to mail send in servlets or jsp?
More...