Java Email Send send(String to, String from, String subject, String text, Properties mailProps)

Here you can find the source of send(String to, String from, String subject, String text, Properties mailProps)

Description

Send an email to a recipient

License

Open Source License

Parameter

Parameter Description
to of type String
from of type String
subject of type String
text of type String
mailProps of type Properties

Exception

Parameter Description

Declaration

public static void send(String to, String from, String subject, String text, Properties mailProps)
        throws MessagingException 

Method Source Code


//package com.java2s;
/*//from w w w.j  a v  a 2s . com
 * Copyright (c) 2012. The Genome Analysis Centre, Norwich, UK
 * MISO project contacts: Robert Davey, Mario Caccamo @ TGAC
 * *********************************************************************
 *
 * This file is part of MISO.
 *
 * MISO is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MISO is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MISO.  If not, see <http://www.gnu.org/licenses/>.
 *
 * *********************************************************************
 */

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

public class Main {
    /**
     * Send an email to a recipient
     *
     * @param to of type String
     * @param from of type String
     * @param subject of type String
     * @param text of type String
     * @param mailProps of type Properties
     * @throws javax.mail.MessagingException
     */
    public static void send(String to, String from, String subject, String text, Properties mailProps)
            throws MessagingException {
        Session mailSession = Session.getDefaultInstance(mailProps);
        Message simpleMessage = new MimeMessage(mailSession);

        InternetAddress fromAddress = new InternetAddress(from);
        InternetAddress toAddress = new InternetAddress(to);

        simpleMessage.setFrom(fromAddress);
        simpleMessage.setRecipient(Message.RecipientType.TO, toAddress);
        simpleMessage.setSubject(subject);
        simpleMessage.setText(text);

        Transport.send(simpleMessage);
    }
}

Related

  1. getMailSender(MimeMessage message)
  2. getSenderEmail(MimeMessage msg)
  3. send(final String username, final String password, final String toEmail, final String subject, final String content)
  4. send(String from, String to, String bcc, String subject, String content)
  5. sendBulkUpdateFailureNotice(final String msgBody)
  6. sendEmail(final String aFromEmailAddr, final String aToEmailAddr, final String aSubject, final String aBody)
  7. sendEmail(Session session, String fromEmail, String toEmail, String subject, String body)
  8. sendEmail(String subject, String text, String receiverEmail)