0

Hello

I have a java program that sends mail to given gmail account.

Now i need to attach some files to mail and send them.

how can i do it??

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by tbone2sk
0
// Set the host smtp address
Properties props = new Properties();
props.put("smtp.host", "smtp.server.com");

// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);

// create a message
Message msg = new MimeMessage(session);

//adding an attachment
DataSource source = new FileDataSource("pathToFile/filename.zip");
msg.setDataHandler(new DataHandler(source));
msg.setFileName("filename.zip");
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.