Skip to main content

Posts

Showing posts from May, 2014

HOW TO SEND EMAIL WITH ATTACHMENT IN JAVA APPLICATION

Simple application to send an email using java application Example : import javax.activation.DataHandler; import javax.activation.FileDataSource; import javax.mail.*; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; import java.util.Date; import java.util.Properties;   public class EmailAttachmentDemo {        public static void main(String[] args) {          EmailAttachmentDemo demo = new EmailAttachmentDemo();          demo.sendEmail();      }        public void sendEmail() {          String from = "email@example.com";          String to = "email@example.com";          String subject = "Important Message";          String bodyText = "This is a important message with attachment";          String filename = "jee-sample/src/main/resources/data.txt";            Properties properties = new Pro

HOW TO SEND AND EMAIL USING JAVA APPLICATION

Simple example to send an email (without attachment ) using java application Syntax : Example : import javax.mail.Session; import javax.mail.Message; import javax.mail.Transport; import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; import javax.mail.internet.InternetAddress; import java.util.Properties;   public class Main {   public static void main(String[] args) {     String from = "user@some-domain.com";     String to = "user@some-domain.com";     String subject = "Hi There...";     String text = "How are you?";       Properties properties = new Properties();     properties.put("mail.smtp.host", "smtp.some-domain.com");     properties.put("mail.smtp.port", "25");     Session session = Session.getDefaultInstance(properties, null);       Message message = new MimeMessage(session);     message.setFrom(new InternetAddress(from));     message.setRecip