Package cli_fmw.utils

Source Code of cli_fmw.utils.ErrorMail

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package cli_fmw.utils;

import com.sun.mail.smtp.SMTPTransport;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

/**
*
* @author finder
*/
public class ErrorMail {
  public void sendMail(final String message) {
    new Thread(new Runnable() {
      @Override
      public void run() {
        sendMailImp(message);
      }
    }).start();
  }

  private void sendMailImp(String message)
  {
    try {
      Properties props = new Properties();
      Session s = Session.getInstance(props);
      Message msg = new MimeMessage(s);
      msg.setFrom(new InternetAddress("support@intelclinic.ru"));
      msg.setRecipients(Message.RecipientType.TO, new InternetAddress[]{new InternetAddress("support@intelclinic.ru")});
      if (ConfigGui.isLoaded()) {
        msg.setSubject("Error report: " + ConfigGui.getInstance().getProgramSampleName());
        msg.setHeader("X-Mailer", ConfigGui.getInstance().getProgramSampleName());
      }
      else {
        msg.setSubject("Error report");
        msg.setHeader("X-Mailer", "Infotechservice");
      }
      MimeBodyPart mbp1 = new MimeBodyPart();
      mbp1.setText(message, "UTF8");
      MimeMultipart mp = new MimeMultipart();
      mp.addBodyPart(mbp1);
      msg.setContent(mp);
      SMTPTransport t = (SMTPTransport)s.getTransport("smtp");
      try {
        t.connect("mail.intelclinic.ru", "support@intelclinic.ru", "mysupport");
        t.sendMessage(msg, msg.getAllRecipients());
      } finally {
        t.close();
      }

    }
    catch (MessagingException ex) {
      MessageBox.asyncShowExceptionOnly(ex, false);
    }
  }
}
TOP

Related Classes of cli_fmw.utils.ErrorMail

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.