Sending an e-mail

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.utl.properties;
public class main
{
public static viod main(String[] args)
{
String from="user@some-domain.com";
String to="user@some-domain.com";
String subject="Hi there......";
String text="Hello";
Properties p=new p();
p.put=("mail.smtp.host",smtp.some-domain.com");
p.put=("mail.smtp.host","25");
Session session=Session.getDefaultInstance(properties,null);
Message message=new MimeMessage(session);
Message.setFrom(new InternetAddress(from));
message.setRecipient(Message.RecipientType.To,new InternetAddress(to));
message.setsubject(subject);
message.setText(text);
Transport.send(message);
}
}
Description:By specifying common DNS with from and to address we can easily send the e-mail.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: