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??

// 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");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.