Below is the code I have for sending email which works great.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package myWorkingFiles;
import org.apache.commons.mail.*;
/*
*
* @author xyz
*/
public class GmailEmailWorking {
public static void main(String[] args) {
String myEmailId = "myEmailId@gmail.com";
String myPassword = "myPassword";
String senderId = "senderId@yahoo.co.in";
try {
Email email = new SimpleEmail();
email.setSmtpPort(587);
email.setAuthenticator(new DefaultAuthenticator(myEmailId, myPassword));
email.setDebug(true);
email.setHostName("smtp.gmail.com");
email.setFrom(myEmailId);
email.setSubject("Hi");
email.setMsg("This is a test mail ... :-)");
email.addTo(senderId);
email.setTLS(true);
email.send();
System.out.println("Mail sent!");
} catch (Exception e) {
System.out.println("Exception :: " + e);
}
}
}
Now I want to send email with attachement as oppose to plain email as shown above.
Please let me know what changes I will need to do? I believe its easy, but sadly Mr. Google is also not helping me.
I have found some links but they are not useful.
A quick search landed me with this ..
http://commons.apache.org/email/userguide.html
Are u trying to search for something different??