basic
import org.apache.commons.mail.*;
import java.net.URL;
import java.net.MalformedURLException;
public class ApacheSendMail {
public static void main(String[] argv) throws EmailException, MalformedURLException {
/* SIMPLEMAIL
SimpleEmail email = new SimpleEmail();
email.setHostName("192.168.1.60");
email.addTo("xx@sss.com", "xx ss");
email.setFrom("me@apache.org", "Me");
email.setSubject("Test message");
email.setMsg("This is a simple test of commons-email");
email.send();
*/
/* MAILWITHATTACHMENT URL
EmailAttachment attachment = new EmailAttachment();
attachment.setURL(new URL("http://www.apache.org/images/asf_logo_wide.gif"));
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("Apache logo");
attachment.setName("Apache logo");
MultiPartEmail email = new MultiPartEmail();
email.setHostName("192.168.1.60");
email.addTo("xx@sss.com", "xx ss");
email.setFrom("me@apache.org", "Me");
email.setSubject("The logo");
email.setMsg("Here is Apache's logo");
email.attach(attachment);
email.send();
*/
EmailAttachment attachment = new EmailAttachment();
attachment.setPath("/test/apache");
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("Picture of Apache");
attachment.setName("Apache");
// Create the email message
MultiPartEmail email = new MultiPartEmail();
email.setHostName("mail.myserver.com");
email.setHostName("192.168.1.60");
email.addTo("xx@sss.com", "xx ss");
email.setFrom("me@apache.org", "Me");
email.setMsg("Here is the picture you wanted");
// add the attachment
email.attach(attachment);
// send the email
email.send();
}
}
import org.apache.commons.mail.*;
import java.net.URL;
import java.net.MalformedURLException;
public class ApacheSendMail {
public static void main(String[] argv) throws EmailException, MalformedURLException {
/* SIMPLEMAIL
SimpleEmail email = new SimpleEmail();
email.setHostName("192.168.1.60");
email.addTo("xx@sss.com", "xx ss");
email.setFrom("me@apache.org", "Me");
email.setSubject("Test message");
email.setMsg("This is a simple test of commons-email");
email.send();
*/
/* MAILWITHATTACHMENT URL
EmailAttachment attachment = new EmailAttachment();
attachment.setURL(new URL("http://www.apache.org/images/asf_logo_wide.gif"));
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("Apache logo");
attachment.setName("Apache logo");
MultiPartEmail email = new MultiPartEmail();
email.setHostName("192.168.1.60");
email.addTo("xx@sss.com", "xx ss");
email.setFrom("me@apache.org", "Me");
email.setSubject("The logo");
email.setMsg("Here is Apache's logo");
email.attach(attachment);
email.send();
*/
EmailAttachment attachment = new EmailAttachment();
attachment.setPath("/test/apache");
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("Picture of Apache");
attachment.setName("Apache");
// Create the email message
MultiPartEmail email = new MultiPartEmail();
email.setHostName("mail.myserver.com");
email.setHostName("192.168.1.60");
email.addTo("xx@sss.com", "xx ss");
email.setFrom("me@apache.org", "Me");
email.setMsg("Here is the picture you wanted");
// add the attachment
email.attach(attachment);
// send the email
email.send();
}
}