Java Email Send sendEmail(String to, String from, String subject, String text)

Here you can find the source of sendEmail(String to, String from, String subject, String text)

Description

send Email

License

Open Source License

Declaration

public static void sendEmail(String to, String from, String subject, String text) throws MessagingException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

public class Main {
    public static void sendEmail(String to, String from, String subject, String text) throws MessagingException {

        Properties props = new Properties();
        props.put("mail.smtp.host", "localhost");
        props.put("mail.smtp.port", "35");

        Session session = Session.getDefaultInstance(props);

        try {/*  www  . j a v a  2  s .c  om*/

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
            message.setSubject(subject);
            message.setText(text);

            Transport.send(message);

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. send(String to, String from, String subject, String text, Properties mailProps)
  2. sendBulkUpdateFailureNotice(final String msgBody)
  3. sendEmail(final String aFromEmailAddr, final String aToEmailAddr, final String aSubject, final String aBody)
  4. sendEmail(Session session, String fromEmail, String toEmail, String subject, String body)
  5. sendEmail(String subject, String text, String receiverEmail)
  6. sendEmail(String toAddress, String subject, String message)
  7. sendMail(Properties props, String recipients[], String subject, String message, String from)
  8. sendMail(Session session, Message message)
  9. sendMail(String filePathName, InternetAddress[] addresses, List> md5cellRows, String today, byte[] report1bytes, byte[] report2bytes, byte[] report3bytes)