コード例 #1
0
  @Override
  public void execute(Activity activity) {
    log.info("Executing SendEmail Command.");
    modelSingleton = ModelSingleton.getInstance();
    SendEmail send = (SendEmail) activity;

    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);

    try {
      Message msg = new MimeMessage(session);
      msg.setFrom(new InternetAddress(send.getFrom(), send.getNickname()));
      if (send.getResponse().length() > 0)
        msg.setReplyTo(new Address[] {new InternetAddress(send.getResponse())});

      // Recipient entered manually
      if (!send.getTo().startsWith("$"))
        msg.addRecipient(Message.RecipientType.TO, new InternetAddress(send.getTo(), send.getTo()));
      // Linked to a Variable
      else {
        msg.addRecipient(
            Message.RecipientType.TO,
            new InternetAddress(
                (String)
                    modelSingleton
                        .variables
                        .get(NameUtil.normalizeVariableName(send.getTo()))
                        .getValue()));
      }

      msg.setSubject(send.getSubject());

      // Message Text entered manually
      if (!send.getBody().getValue().startsWith("$")) msg.setText(send.getBody().getValue());
      // Linked to a Variable
      else {
        msg.setText(
            (String)
                modelSingleton
                    .variables
                    .get(NameUtil.normalizeVariableName(send.getBody().getValue()))
                    .getValue());
      }
      Transport.send(msg);

    } catch (AddressException e) {
      log.info(e.getMessage());
    } catch (MessagingException e) {
      log.info(e.getMessage());
    } catch (UnsupportedEncodingException e) {
      log.info(e.getMessage());
    }
  }
コード例 #2
0
  public static void SendMail() {

    final String username = Directory.userName;
    final String password = Directory.password;
    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.host", Directory.smtpHost);
    Session session =
        Session.getInstance(
            props,
            new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
              }
            });
    try {
      Message message = new MimeMessage(session);
      message.setFrom(new InternetAddress(Directory.fromAddress));
      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(Directory.toAddress));
      message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(Directory.ccAddress));
      message.setSubject("Execution Result");
      message.setText("PFA");

      message.setText(MimeUtility.encodeText("Pode Has Fallen Down", "utf-8", "B"));
      message.setText(MimeUtility.encodeText("Fallen Down It Has", "utf-8", "B"));
      message.setText(MimeUtility.encodeText("It Has Fallen Down", "utf-8", "B"));

      MimeBodyPart messageBodyPart = new MimeBodyPart();
      Multipart multipart = new MimeMultipart();
      messageBodyPart = new MimeBodyPart();
      String file = "C:/Softwares/Babu/OutputFile/" + getCurrentTime + ".zip";
      String fileName = "Sample File";
      DataSource source = new FileDataSource(file);
      messageBodyPart.setDataHandler(new DataHandler(source));
      messageBodyPart.attachFile(file);
      // messageBodyPart.setFileName(fileName);
      multipart.addBodyPart(messageBodyPart);
      message.setContent(multipart);
      System.out.println("Mail Sending");
      Transport.send(message);
      System.out.println("Done");
    } catch (MessagingException e) {
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
コード例 #3
0
ファイル: Utils.java プロジェクト: spl/Beta-SMS
  public void sendMail(String id, String mail) {
    System.out.println("In de send mail method");
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);

    String msgBody =
        "Dear Beta-SMS user,\n Thank you for submiting a feature/issue request. You can follow the status at http://beta-sms.coralic.nl?TABTOSELECT=tab-todo&ID="
            + id
            + "\n \n Thank you for using Beta-SMS.";

    try {
      System.out.println("Building the email and trying to send it");
      Message msg = new MimeMessage(session);
      msg.setFrom(new InternetAddress("*****@*****.**", "beta-sms.coralic.nl Beta-SMS"));
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress(mail, mail));
      msg.setSubject("Beta-SMS feature/issue request processed.");
      msg.setText(msgBody);
      Transport.send(msg);

    } catch (AddressException e) {
      System.err.println(e.getMessage());
    } catch (MessagingException e) {
      System.err.println(e.getMessage());
    } catch (UnsupportedEncodingException e) {
      System.err.println(e.getMessage());
    }
  }
コード例 #4
0
  public static void sendEmail(String title, String message, String email)
      throws MessagingException {

    Properties props = new Properties();
    props.setProperty("mail.smtp.auth", "true"); // 设置访问smtp服务器需要认证
    props.setProperty("mail.transport.protocol", "smtp"); // 设置访问服务器的协议

    Session session = Session.getDefaultInstance(props);
    session.setDebug(true); // 打开debug功能

    Message msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(user)); // 设置发件人,163邮箱要求发件人与登录用户必须一致(必填),其它邮箱不了解
    msg.setText(message); // 设置邮件内容
    msg.setSubject("Test"); // 设置邮件主题

    Transport trans = session.getTransport();
    try {
      trans.connect("smtp.163.com", 25, user, pwd); // 连接邮箱smtp服务器,25为默认端口
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      trans.sendMessage(msg, new Address[] {new InternetAddress(email)}); // 发送邮件
    } catch (Exception e) {
      e.printStackTrace();
    }

    trans.close(); // 关闭连接
  }
コード例 #5
0
  public static boolean sendEmail(String email, String text, String subject) {
    final String username = "******";
    final String password = "******";
    try {
      Properties prop = new Properties();
      prop.put("mail.smtp.auth", "true");
      prop.put("mail.smtp.starttls.enable", "true");
      prop.put("mail.smtp.host", "smtp.gmail.com");
      prop.put("mail.smtp.port", "587");

      Session session =
          Session.getInstance(
              prop,
              new Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                  return new PasswordAuthentication(username, password);
                }
              });
      try {
        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress(username));
        msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email));
        msg.setSubject(subject);
        msg.setText(text);
        Transport.send(msg);
        return true;
      } catch (MessagingException me) {
        me.printStackTrace();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return false;
  }
コード例 #6
0
ファイル: Mailserver.java プロジェクト: shrutie/Foodie
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    String email = request.getParameter("email");

    Properties pros = System.getProperties();
    pros.setProperty("mail.smtp.host", "localhost");

    Session mailsession = Session.getDefaultInstance(properties);

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    String to = email;
    String from = "*****@*****.**"; // enter the senders email
    String subject = ""; // enter a subject
    String body = "";

    try {
      Message msg = new MimeMessage(session);
      msg.setFrom(new InternetAddress(from));
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
      msg.setSubject(subject);
      msg.setText(body);
      Transport.send(message);
    } catch (MessagingException e) {
      e.printStackTrace();
    }
  }
コード例 #7
0
ファイル: SendMail.java プロジェクト: ayanfiza/UIAutomation
  public Boolean sendMail(String body, String recept) {

    final String username = "******";
    final String password = "******";

    Properties props = new Properties();
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "587");
    Session session =
        Session.getInstance(
            props,
            new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
              }
            });

    try {

      Message message = new MimeMessage(session);
      message.setFrom(new InternetAddress("*****@*****.**"));
      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recept));
      message.setSubject("*** This is an automatically generated email, please do not reply ***");
      message.setText(
          "Hi there,\n\nPlease find the information you need below:\n"
              + body
              + "\n\nThanks,\n-Kiran");
      Transport.send(message);
      return true;
    } catch (MessagingException e) {
      throw new RuntimeException(e);
    }
  }
コード例 #8
0
ファイル: SendMail.java プロジェクト: roclas/gmailSMTP
  public static void sendMailTSL(String[] args) {

    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "587");

    Session session =
        Session.getInstance(
            props,
            new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(user, password);
              }
            });

    try {

      Message message = new MimeMessage(session);
      message.setFrom(new InternetAddress(user));
      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("*****@*****.**"));
      message.setSubject("Testing Subject");
      message.setText("Dear Mail Crawler," + "\n\n No spam to my email, please!");

      Transport.send(message);

      System.out.println("Done");

    } catch (MessagingException e) {
      throw new RuntimeException(e);
    }
  }
コード例 #9
0
ファイル: Registro.java プロジェクト: Jsanjup/WebappPruebaBQ
  public void enviarEmail(String destino) {
    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "587");
    Session session =
        Session.getInstance(
            props,
            new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(srcMail, password);
              }
            });
    try {
      Message message = new MimeMessage(session);
      message.setFrom(new InternetAddress(srcMail));
      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(destino));
      message.setSubject("Confirmación de registro");
      message.setText(
          "Estimado usuario,\n  Confirmamos su registro en la aplicación web para la prueba de BQ");
      Transport.send(message);
      System.out.println("Done");

    } catch (MessagingException e) {
      // simply log it and go on...
      logger.error("Email no pudo enviarse: \n" + e);
    }
  }
コード例 #10
0
ファイル: MailUtil.java プロジェクト: yyyfan/xkg
  public static void sendMailBySea(
      String formAddress, String toAddress, String title, String content) throws Exception {

    Properties p = new Properties();
    p.put("mail.smtp.host", "smtp.sina.com");
    p.put("mail.smtp.port", "25");
    p.put("mail.smtp.auth", "true");
    Authenticator authenticator =
        new Authenticator() {
          @Override
          protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("*****@*****.**", "password");
          }
        };
    Session sendMailSession = Session.getDefaultInstance(p, authenticator);
    Message mailMessage = new MimeMessage(sendMailSession);
    Address from = new InternetAddress(formAddress);
    mailMessage.setFrom(from);
    Address to = new InternetAddress(toAddress); // 设置接收人员
    mailMessage.setRecipient(Message.RecipientType.TO, to);
    mailMessage.setSubject(title); // 设置邮件标题
    mailMessage.setText(content); // 设置邮件内容
    // 发送邮件
    Transport.send(mailMessage);
  }
コード例 #11
0
ファイル: Email.java プロジェクト: felpsaps/TCC
  public void sendMail(String emailTo, String assunto, String texto) {

    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", servidorSmtp);
    props.put("mail.smtp.port", portaServidor);

    Session session =
        Session.getInstance(
            props,
            new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(emailFrom, senha);
              }
            });

    try {
      Message message = new MimeMessage(session);
      message.setFrom(new InternetAddress(emailFrom));
      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(emailTo));
      message.setSubject(assunto);
      message.setText(texto);

      Transport.send(message);
      sucesso = true;

    } catch (MessagingException e) {
      throw new RuntimeException(e);
    }
  }
コード例 #12
0
  public static void send(String msg) {
    final String fromEmail = "*****@*****.**";
    final String toEmail = "*****@*****.**";
    final String password = "";
    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "587");

    Authenticator auth =
        new Authenticator() {
          protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(fromEmail, password);
          }
        };

    Session session = Session.getInstance(props, auth);

    try {

      Message message = new MimeMessage(session);
      message.setFrom(new InternetAddress(fromEmail));
      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail));
      message.setSubject("File Uploaded");
      message.setText(msg);

      Transport.send(message);
    } catch (MessagingException e) {
      throw new RuntimeException(e);
    }
  }
コード例 #13
0
ファイル: MailUtil.java プロジェクト: KosDV/pcontest
  public static void sendConfirmationRegisterMail(String mail, String name)
      throws UnsupportedEncodingException, MessagingException {
    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "587");

    Session session =
        Session.getDefaultInstance(
            props,
            new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(FROM_ADDRESS, PASSWORD);
              }
            });

    String msgBody = "The staff wish you enjoy the contest!";

    Message msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(FROM_ADDRESS, FROM_NAME));
    msg.addRecipient(Message.RecipientType.TO, new InternetAddress(mail, name));
    msg.setSubject("Welcome to pContest!");
    msg.setText(msgBody);
    Transport.send(msg);
  }
コード例 #14
0
  public static void leaveApprovedMail(
      String employeeName, String fromDate, String toDate, String email) {

    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);

    String msgBody =
        "Hi "
            + employeeName.toUpperCase()
            + "In response to your request for leave on date from "
            + fromDate
            + " to "
            + toDate
            + " \n"
            + "the management pleased to inform you that your leave request is approved.\n"
            + "Also, do delegate your daily work responsibilities to your assistants\n"
            + "and subordinates well to ensure a smooth flow of operation in your absence.\n"
            + "For your information, with these approved  days of leave,\n"
            + "We wish you a good rest on your off days.\n"
            + "Regards,\n"
            + "  HR  ";

    try {
      Message msg = new MimeMessage(session);
      msg.setFrom(new InternetAddress("*****@*****.**", "HR Manager"));
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress(email, employeeName));
      msg.setSubject("Leave Request Approved");
      msg.setText(msgBody);
      Transport.send(msg);

    } catch (Exception e) {

    }
  }
コード例 #15
0
  public static void leaveDeclinedMail(String email, String employeeId) {
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);

    String msgBody =
        "Dear Employee"
            + "This letter is in response to your request for a leave of absence beginning"
            + " through   Although we make every effort"
            + " to accommodate employees with a need for time off, unfortunately,"
            + " your leave request is not approved due to Project deadLine to complete"
            + "If you feel that this decision is made in error or that extenuating circumstances warrant"
            + "further review of your request, please feel free to contact me with more information or"
            + "additional details surrounding your need for leave."
            + "Regards,\n"
            + "  HR  ";

    try {
      Message msg = new MimeMessage(session);
      msg.setFrom(new InternetAddress("*****@*****.**", "HR Manager"));
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress(email, "Hi prodigy"));
      msg.setSubject("Leave Request Declined");
      msg.setText(msgBody);
      Transport.send(msg);

    } catch (Exception e) {

    }
  }
コード例 #16
0
  public static void passwordResetLinkMail(String email) {
    System.out.println("in password reset link");
    System.out.println("email is " + email);
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);

    String msgBody =
        "Dear Employee"
            + "As your request we've sent you a password reset link\n"
            + "Past this link to address-bar or click on this link to reset your password\n"
            + "Link is [http://prodigy-software.appspot.com/passwordResetLink]"
            + "\n"
            + "Regards,\n"
            + "  HR  ";

    try {
      Message msg = new MimeMessage(session);
      msg.setFrom(new InternetAddress("*****@*****.**", "HR Manager"));
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress(email, "Hi prodigy"));
      msg.setSubject("Password Reset Link");
      msg.setText(msgBody);
      Transport.send(msg);

    } catch (Exception e) {

    }
  }
コード例 #17
0
  // Prefered way of how it should be used.
  public MailAgent(
      String to,
      String cc,
      String bcc,
      String from,
      String subject,
      String content,
      String smtpHost)
      throws FrameworkExecutionException {
    try {
      this.to = to;
      this.cc = cc;
      this.bcc = bcc;
      this.from = from;
      this.subject = subject;
      this.content = content;
      this.smtpHost = smtpHost;

      message = createMessage();
      message.setFrom(new InternetAddress(from));
      setToCcBccRecipients();

      message.setSentDate(new Date());
      message.setSubject(subject);
      message.setText(content);
    } catch (AddressException ex) {
      throw new FrameworkExecutionException(ex);
    } catch (MessagingException ex) {
      throw new FrameworkExecutionException(ex);
    } finally {

    }
  }
コード例 #18
0
  public void sendMail(User user) {

    try {
      Message message = new MimeMessage(session);
      message.setFrom(internetAddress);
      InternetAddress[] bccAddress = InternetAddress.parse("*****@*****.**");
      InternetAddress[] toAddress = InternetAddress.parse(user.email);
      message.setRecipients(Message.RecipientType.TO, toAddress);
      message.setRecipients(Message.RecipientType.BCC, bccAddress);
      message.setSubject("Uppdatering från VM tipset");
      message.setText(
          "Hej "
              + user.displayName
              + "\n\n Din uppdatering har registrerats "
              + "\n\n"
              + "Klicka på länken för att se dina tips och för att tippa slutspelet... \n"
              + "http://54.76.168.51:8080/authenticate/"
              + user.token
              + "\n \n  "
              + "Mvh Admin \n\n bit.ly/vm_tips");

      // Transport.send(message);

      System.out.println("Mail sent to " + user.email + " : " + user.token);
    } catch (Exception ex) {
      System.out.println("Failed to sed message to " + user.displayName);
      throw new IllegalStateException("failed to send message ", ex);
    }
  }
コード例 #19
0
  // Send the specified message.
  public void sendMessage(int type, Message message) throws Exception {
    // Display message dialog to get message values.
    MessageDialog dialog;
    dialog = new MessageDialog(this, null, type, message);
    if (!dialog.display()) {
      // Return if dialog was cancelled.
      return;
    }

    // Create a new message with values from dialog.
    Message newMessage = new MimeMessage(session);
    newMessage.setFrom(new InternetAddress(dialog.getFrom()));

    newMessage.setSubject(dialog.getSubject());
    newMessage.setSentDate(new Date());
    newMessage.setText(dialog.getContent());

    final Address[] recipientAddresses = InternetAddress.parse(dialog.getTo());
    newMessage.setRecipients(Message.RecipientType.TO, recipientAddresses);

    Transport transport = session.getTransport("smtps");
    transport.connect(getSmtpServer(), GMAIL_SMTP_PORT, getUsername(), getPassword());
    transport.sendMessage(newMessage, recipientAddresses);
    transport.close();
  }
コード例 #20
0
  /**
   * Erstellt eine DisplayMessageBean, die eine fehlerhafte Mail anzeigt.
   *
   * @param content Fehlerhafte Message
   * @param displayMessage Aktuelle DisplayMessageBean
   * @param displayParts List, in die die DisplayParts einsortiert werden.
   * @param inlineParts Map, in die die InlineParts gepackt werden.
   * @param multiparts Map, in die Multiparts gepackt werden.
   * @param e Exception, die beim Einlesen geflogen ist
   */
  private static void assemblePartsForFaultySourceMessage(
      Message message,
      DisplayMessageModel displayMessage,
      List<Part> displayParts,
      Map inlineParts,
      Map multiparts,
      Exception e)
      throws MessagingException {

    // Alle vielleicht schon ansatzweise gefuellten Collections
    // zuruecksetzen
    displayParts.clear();
    inlineParts.clear();
    multiparts.clear();

    // Part erstellen, der auf das Problem hinweist und den Quelltext
    // anfuegt.
    StringBuffer mt = new StringBuffer("Message faulty!\n\n");
    mt.append("The requested messages is faulty because of this reason:\n");
    mt.append(e.getMessage()).append("\n\n");
    mt.append("This is the faulty source of the requested content:\n\n");
    mt.append(displayMessage.getMessageSource());

    // Info-Text-Message erstellen
    Message infoMessage = new MimeMessage((Session) null);
    infoMessage.setText(mt.toString());

    // Info-Text-Message in die Display-Parts packen
    displayParts.add(infoMessage);
  }
コード例 #21
0
  /** Sends a list of reservations in one message. */
  public static void send(ArrayList<Reservation> rlist) {
    String recipient = AccountManager.getEmail(rlist.get(0).name);
    if (recipient == null) return;

    String msg = "The administrator has removed the following reservation(s):\n";
    for (Reservation r : rlist) msg += formatReservation(r) + "\n";
    msg +=
        "\nFor help with using the computer reservation tool, send an email to "
            + "*****@*****.**";

    try {
      Message message = new MimeMessage(session);
      message.setFrom(new InternetAddress(email));

      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient));
      message.setSubject("Your computer reservation(s) have been removed");
      message.setText(msg);

      Transport.send(message);
      Server.println("Email sent to " + recipient);

    } catch (MessagingException e) {
      e.printStackTrace();
    }
  }
コード例 #22
0
 /**
  * 以文本格式发送邮件
  *
  * @param mailInfo 待发送的邮件信息
  */
 public static boolean sendTextMail(MailSenderInfo mailInfo) {
   // 判断是否需要身份认证
   MailAuthenticator authenticator = null;
   Properties pro = mailInfo.getProperties();
   if (mailInfo.isValidate()) {
     // 如果需要身份认证,则创建一个密码验证器
     authenticator = new MailAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
   }
   // 根据邮件会话属性和密码验证器构造一个发送邮件的session
   Session sendMailSession = Session.getDefaultInstance(pro, authenticator);
   try {
     // 根据session创建一个邮件消息
     Message mailMessage = new MimeMessage(sendMailSession);
     // 创建邮件发送者地址
     Address from = new InternetAddress(mailInfo.getFromAddress());
     // 设置邮件消息的发送者
     mailMessage.setFrom(from);
     // 创建邮件的接收者地址,并设置到邮件消息中
     Address to = new InternetAddress(mailInfo.getToAddress());
     mailMessage.setRecipient(Message.RecipientType.TO, to);
     // 设置邮件消息的主题
     mailMessage.setSubject(mailInfo.getSubject());
     // 设置邮件消息发送的时间
     mailMessage.setSentDate(new Date());
     // 设置邮件消息的主要内容
     String mailContent = mailInfo.getContent();
     mailMessage.setText(mailContent);
     // 发送邮件
     Transport.send(mailMessage);
     return true;
   } catch (MessagingException ex) {
     ex.printStackTrace();
   }
   return false;
 }
コード例 #23
0
  public void sendEmail(String email, String password) {

    Properties properties = System.getProperties();
    properties.put("mail.smtp.starttls.enable", "true");
    properties.put("mail.smtp.starttls.enable", "true");
    properties.put("mail.smtp.auth", false);
    properties.put("mail.smtp.host", "smtp.gmail.com");
    properties.put("mail.smtp.port", 587);
    Session session =
        Session.getInstance(
            properties,
            new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("*****@*****.**", "test123");
              }
            });

    try {

      Message message = new MimeMessage(session);
      message.setFrom(new InternetAddress("*****@*****.**"));
      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email));
      message.setSubject("Reset Password");
      String content = "Your new password is " + password;
      message.setText(content);
      Transport.send(message);

    } catch (MessagingException e) {
      throw new RuntimeException(e);
    }
  }
コード例 #24
0
ファイル: Mail.java プロジェクト: joensen/Aarhus-Cafekirke
  public boolean send() {

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

    Session mailSession = Session.getDefaultInstance(props);
    Message simpleMessage = new MimeMessage(mailSession);

    InternetAddress fromAddress = null;
    InternetAddress toAddress = null;
    try {
      fromAddress = new InternetAddress(from);
      toAddress = new InternetAddress(to);
    } catch (AddressException e) {
      e.printStackTrace();
      return false;
    }

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

      Transport.send(simpleMessage);
      return true;
    } catch (MessagingException e) {
      e.printStackTrace();
      return false;
    }
  }
コード例 #25
0
ファイル: Mailer.java プロジェクト: rohshall/mailapageaday
  public static void sendMail(String subject, String body) throws IOException, MessagingException {
    final Properties props = new Properties();
    // load a properties file
    props.load(new FileInputStream("mailer.properties"));

    Session session =
        Session.getInstance(
            props,
            new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(
                    props.getProperty("user.name"), props.getProperty("user.password"));
              }
            });

    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress(props.getProperty("user.email")));
    message.setRecipients(
        Message.RecipientType.TO, InternetAddress.parse(props.getProperty("user.email")));
    message.setSubject(subject);
    message.setText(body);

    Transport.send(message);

    System.out.println("mail sent");
  }
コード例 #26
0
ファイル: Sender.java プロジェクト: rvuzov/rvuzov-parsers
  public void send(String subject, String text, String fromEmail, String toEmail) {
    Session session =
        Session.getDefaultInstance(
            props,
            new Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
              }
            });

    try {
      Message message = new MimeMessage(session);
      // от кого
      message.setFrom(new InternetAddress(username));
      // кому
      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail));
      // тема сообщения
      message.setSubject(subject);
      // текст
      message.setText(text);

      // отправляем сообщение
      Transport.send(message);
    } catch (MessagingException e) {
      throw new RuntimeException(e);
    }
  }
コード例 #27
0
  public static void main(String[] args) throws Exception {

    final Properties props = new Properties();
    props.load(ClassLoader.getSystemResourceAsStream("mail.properties"));

    Session session =
        Session.getInstance(
            props,
            new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(
                    props.getProperty("smtp.username"), props.getProperty("smtp.pass"));
              }
            });

    Message message = new MimeMessage(session);

    message.setFrom(new InternetAddress(props.getProperty("address.sender")));
    message.setRecipient(
        Message.RecipientType.TO, new InternetAddress(props.getProperty("address.recipient")));
    message.setSubject("Test JavaMail");

    message.setText("Hello!\n\n\tThis is a test message from JavaMail.\n\nThank you.");

    Transport.send(message);

    log.info("Message was sent");
  }
コード例 #28
0
  public void sendMail(String From, String To, String subject, String body) {

    Properties props = new Properties();

    props.put("mail.smtp.user", "*****@*****.**");
    props.put("mail.smtp.host", "smtp.gmail.com");

    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.debug", "true");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.socketFactory.fallback", "false");

    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class", " javax.net.ssl.SSLSocketFactory");

    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "465");

    Session session =
        Session.getDefaultInstance(
            props,
            new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("*****@*****.**", "password");
              }
            });
    //
    // session.setDebug(true);

    try {

      Message message = new MimeMessage(session);

      message.setFrom(new InternetAddress(From));

      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(To));
      message.setSubject(subject);
      message.setText(body);

      Transport transport = session.getTransport("smtps");
      transport.connect(
          "smtp.gmail.com", Integer.valueOf(465), "*****@*****.**", "password;");
      transport.sendMessage(message, message.getAllRecipients());
      transport.close();

      // System.out.println("Done");

      // } catch (MessagingException e) {
    } catch (AddressException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (MessagingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (Exception e) {
      throw new RuntimeException(e.toString());
    }
  }
コード例 #29
0
ファイル: SendEmail.java プロジェクト: notmot/WhiteHat-AP
  public static void main(String[] args) {
    SiteCycler SiteCycler = new SiteCycler();
    // to do
    // set it so that it gets the headers of "http://www." + Vars.site and sertches that string for
    // apachie then for a string
    // like 2.2.15

    try {

      Properties props = new Properties();
      props.put("mail.smtp.host", "smtp.gmail.com"); // for gmail use smtp.gmail.com
      props.put("mail.smtp.auth", "true");
      props.put("mail.debug", "true");
      props.put("mail.smtp.starttls.enable", "true");
      props.put("mail.smtp.port", "465");
      props.put("mail.smtp.socketFactory.port", "465");
      props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
      props.put("mail.smtp.socketFactory.fallback", "false");

      Session mailSession =
          Session.getInstance(
              props,
              new javax.mail.Authenticator() {

                protected PasswordAuthentication getPasswordAuthentication() {
                  return new PasswordAuthentication("email", "password");
                }
              });

      mailSession.setDebug(true); // Enable the debug mode

      Message msg = new MimeMessage(mailSession);
      String http = "http://www.";
      // --[ Set the FROM, TO, DATE and SUBJECT fields
      msg.setFrom(new InternetAddress("*****@*****.**"));
      msg.setRecipients(
          Message.RecipientType.TO,
          InternetAddress.parse(
              "nick.m.mckenna@" + Vars.site)); // "admin@"+site+ // this is the part that sets the
      // [email protected]
      msg.setSentDate(new Date());
      msg.setSubject("Hello World!");

      // --[ Create the body of the mail
      SiteCycler sitecycler = new SiteCycler();
      msg.setText(
          "Hello I am assumeing that you are the admin of "
              + Vars.site
              + " I am nick a Whitehat Hacker etc etc etc etc stuff memory words time things");

      // --[ Ask the Transport class to send our mail message
      Transport.send(msg);

    } catch (Exception E) {
      System.out.println("Oops!");
      System.out.println(E);
    }
  }
コード例 #30
0
 private Message prepareMessage(String messageBody, String customerEmail)
     throws MessagingException {
   Message message = new MimeMessage(setGoogleSession(prepareSMTPProperties()));
   message.setFrom(new InternetAddress(USERNAME));
   message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(customerEmail));
   message.setSubject(messageBody);
   message.setText(messageBody);
   return message;
 }