Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: How to send E-Mail

Java: How to send E-Mail
{filelink=1009}

import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class EmailJava
 {
  // Send email to contact
  public static void send_email(String serveurSTMP, int portSTMP, String from, String to, String subject,
      String message) throws Exception
    {
         String username = "myusername";
		String password = "mypassword";	
    java.util.Properties props = new java.util.Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    Session session = Session.getDefaultInstance(props, null);
    Transport transport = session.getTransport("smtp");
    transport.connect(serveurSTMP, portSTMP, username, password);
    Message msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(from));
    msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
    msg.setSubject(subject);
    msg.setText(message);
    Transport.send(msg);
  }
  public static void main(String[] args) throws Exception {
    send_email("smtp.gmail.com", 465, "de@gm.com", "ae@rmail.com", "invitation", "my message");
  }
}

Users who found this page were searching for:

  • string hashcode in perl
  • python compare strings
  • perl calculate the number of days between two dates
  • how to send a mail from java file

No comments yet.

Leave a Comment