Пример #1
0
 static void editMessageSimple(CommandSender sender, String[] args) {
   SimpleEmail email = simpleEmail.get(sender.getName());
   try {
     email.setMsg(Utils.implode(args, " "));
   } catch (EmailException e) {
     sendErrorMessage(sender, e);
     return;
   }
   LogHelper.showInfo("emailMessageSet", sender);
   simpleEmail.put(sender.getName(), email);
 }
Пример #2
0
 static String[] composeReadableRecipientList(SimpleEmail email) {
   String[] RRL = {"To: ", "Cc: ", "Bcc: "};
   Iterator<String> toIT = Utils.noGenericTypeToStringType(email.getToAddresses()).iterator(),
       ccIT = Utils.noGenericTypeToStringType(email.getCcAddresses()).iterator(),
       bccIT = Utils.noGenericTypeToStringType(email.getBccAddresses()).iterator();
   while (toIT.hasNext()) {
     RRL[0] += toIT.next() + ", ";
   }
   while (ccIT.hasNext()) {
     RRL[1] += ccIT.next() + ", ";
   }
   while (bccIT.hasNext()) {
     RRL[2] += bccIT.next() + ", ";
   }
   return RRL;
 }
Пример #3
0
 /**
  * @param username 用户名
  * @param ip 用户登录时的Ip
  * @param time 用户登录的时间
  */
 public void sendEmail(String username, String ip, String time) {
   SimpleEmail simpleEmail = new SimpleEmail();
   simpleEmail.setAuthentication("*****@*****.**", "Q2889144");
   simpleEmail.setHostName("smtp.126.com");
   simpleEmail.setSmtpPort(25);
   simpleEmail.setCharset("utf-8");
   try {
     simpleEmail.setFrom("*****@*****.**");
     simpleEmail.addTo("*****@*****.**");
     simpleEmail.setMsg(time + ",用户:" + username + "在" + ip + "登录");
     simpleEmail.setSubject("开会");
     simpleEmail.send();
   } catch (EmailException e) {
     e.printStackTrace();
   }
 }
 @Override
 public void sendEmail() {
   try {
     simpleEmail.send();
   } catch (EmailException e) {
     throw new FailedNotificationException(e);
   }
 }
Пример #5
0
 @Override
 public void send() {
   try {
     simpleEmail.send();
   } catch (EmailException e) {
     System.out.println("Email send error " + e);
   }
 }
Пример #6
0
 // UTILS FOR EMAIL STUFF
 static SimpleEmail setAuthentication(SimpleEmail email) {
   if (!(CommandsEX.getConf().getString("Email.Username").isEmpty()
       && CommandsEX.getConf().getString("Email.Password").isEmpty())) {
     email.setAuthentication(
         CommandsEX.getConf().getString("Email.Username"),
         CommandsEX.getConf().getString("Email.Password"));
   }
   return email;
 }
Пример #7
0
  public void send() {
    SimpleEmail email = new SimpleEmail();
    email.setTLS(TLS); // 是否TLS校验,,某些邮箱需要TLS安全校验,同理有SSL校验
    email.setHostName(hostName);
    try {
      email.setFrom(sendMailAddress, sendMailAddress);
      email.setAuthentication(sendMailAddress, mailPassword);
      email.setCharset("utf-8"); // 解决中文乱码问题
      email.setSubject(mailTitle); // 标题
      email.setMsg(mailContent); // 内容
      for (int i = 0; i < getMailAddress.length; ++i) {
        email.addTo(getMailAddress[i]); // 接收方
        email.send();
      }

    } catch (EmailException e) {
      //  e.printStackTrace();
    }
  }
Пример #8
0
 static void editRecipientSimple(
     CommandSender sender, String emailString, RecipientAction action) {
   SimpleEmail email = simpleEmail.get(sender.getName());
   switch (action) {
     case ADD:
       try {
         email.addTo(emailString);
       } catch (EmailException e) {
         sendErrorMessage(sender, e);
         return;
       }
       LogHelper.showInfo("emailRecipientAdd", sender);
     case ADD_BCC:
       try {
         email.addBcc(emailString);
       } catch (EmailException e) {
         sendErrorMessage(sender, e);
         return;
       }
       LogHelper.showInfo("emailRecipientAdd", sender);
     case ADD_CC:
       try {
         email.addCc(emailString);
       } catch (EmailException e) {
         sendErrorMessage(sender, e);
         return;
       }
       LogHelper.showInfo("emailRecipientAdd", sender);
     case DELETE:
       try {
         email = removeRecipient(email, emailString);
       } catch (EmailException e) {
         sendErrorMessage(sender, e);
         return;
       }
       LogHelper.showInfo("emailRecipientDeleted", sender);
     case LIST:
       sender.sendMessage(composeReadableRecipientList(email));
     default:
   }
   simpleEmail.put(sender.getName(), email);
 }
Пример #9
0
 public static void compose(CommandSender sender, String type) {
   if (inProgress(sender.getName())) {
     LogHelper.showWarning("emailAlreadyInProgress", sender);
     return;
   }
   if (type.equalsIgnoreCase("simple")) {
     SimpleEmail email = new SimpleEmail();
     email.setHostName(CommandsEX.getConf().getString("Email.Host"));
     try {
       email.setFrom(CommandsEX.getConf().getString("Email.From"));
     } catch (EmailException e) {
       sendErrorMessage(sender, e);
       return;
     }
     email = setAuthentication(email);
     simpleEmail.put(sender.getName(), email);
   } else if (type.equalsIgnoreCase("attachment")) {
     MultiPartEmail email = new MultiPartEmail();
     email.setHostName(CommandsEX.getConf().getString("Email.Host"));
     try {
       email.setFrom(CommandsEX.getConf().getString("Email.From"));
     } catch (EmailException e) {
       sendErrorMessage(sender, e);
       return;
     }
     email = setAuthentication(email);
     multiEmail.put(sender.getName(), email);
   } else if (type.equalsIgnoreCase("html")) {
     HtmlEmail email = new HtmlEmail();
     email.setHostName(CommandsEX.getConf().getString("Email.Host"));
     try {
       email.setFrom(CommandsEX.getConf().getString("Email.From"));
     } catch (EmailException e) {
       sendErrorMessage(sender, e);
       return;
     }
     email = setAuthentication(email);
     htmlEmail.put(sender.getName(), email);
   }
   LogHelper.showInfo("emailCreated", sender);
 }
Пример #10
0
 public static void mail() throws EmailException {
   SimpleEmail email = new SimpleEmail();
   email.setFrom("*****@*****.**");
   email.addTo("*****@*****.**");
   email.setSubject("メールのテスト");
   email.setMsg("メールの本文です。本文です。");
   email.setContent("メールの本文です。本文です。", "text/plain; charset=ISO-2022-JP");
   email.setCharset("ISO-2022-JP");
   Mail.send(email);
 }
Пример #11
0
  public void enviaEmailUsuario() {
    FacesContext context = FacesContext.getCurrentInstance();
    HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
    Usuario usuario = (Usuario) session.getAttribute("usuarioLogado");
    SimpleEmail email = new SimpleEmail();
    // email.setSSLOnConnect(true);
    email.setHostName("smtp-pel.lifemed.com.br");
    //   email.setSslSmtpPort("465");
    email.setSmtpPort(587);
    email.setAuthenticator(new DefaultAuthenticator("anderson.freitas", "nub10fr31t4s"));
    try {
      email.setFrom("*****@*****.**");
      email.setDebug(true);

      email.setSubject(getSubject());
      email.setMsg(mensagem);
      email.addTo(remetente);

      email.send();
    } catch (EmailException ex) {
      ex.printStackTrace();
    }
  }
  private void enviaEmailSimples() throws RuntimeException {
    try {
      SimpleEmail email = new SimpleEmail();
      email.setHostName("127.0.0.1");
      email.addTo("*****@*****.**", "Gilberto");
      email.setFrom("*****@*****.**", "I'm");
      email.setSubject("Test -> Email simples");
      email.setMsg("Test of Email by using commons-email");
      email.setAuthentication("demo", "123456");
      // email.setSmtpPort(465);
      // email.setSSL(false);
      // email.setTLS(false);
      email.send();
      // after sent email wait for a pool of connection by spring integration
      Thread.sleep(20000);

    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
Пример #13
0
 public static void sendEmail(String feedbackTo, String subject, String message) {
   SimpleEmail email = new SimpleEmail();
   try {
     email.setHostName(
         ApplicationConfig.getInstance()
             .getProperty(Constants.CONFIG_PROPERTIES.FEEDBACK_EMAIL_HOST));
     email.addTo(feedbackTo);
     email.setFrom(
         ApplicationConfig.getInstance().getProperty(Constants.CONFIG_PROPERTIES.FEEDBACK_FROM));
     email.setSubject(subject);
     email.setMsg(message);
     email.send();
   } catch (EmailException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Пример #14
0
  /**
   * 메일을 발송한다.
   *
   * <p>when 메일발송 페이지에서 발송시
   *
   * <p>입력폼으로부터 보내는 메일주소, 받는사람 제목, 본문내용을 입력받고 {@code email} 객체에 할당한다. 메일을 발송하고 결과를 {@code sended}에
   * 할당한다. {@code writeMail()} 을 통해 메일 전송여부와 오류메세지를 설정하고 메일발송 페이지로 이동한다.
   *
   * @return the result
   * @throws EmailException the email exception
   * @see {@link SiteApp#writeMail(String, boolean)}
   */
  public static Result sendMail() throws EmailException {
    SimpleEmail email = new SimpleEmail();

    Map<String, String[]> formData = request().body().asFormUrlEncoded();
    email.setFrom(utils.HttpUtil.getFirstValueFromQuery(formData, "from"));
    email.setSubject(utils.HttpUtil.getFirstValueFromQuery(formData, "subject"));
    email.addTo(utils.HttpUtil.getFirstValueFromQuery(formData, "to"));
    email.setMsg(utils.HttpUtil.getFirstValueFromQuery(formData, "body"));
    email.setCharset("utf-8");

    String errorMessage = null;
    boolean sended;
    String result = Mailer.send(email);
    Logger.info(">>>" + result);
    sended = true;
    return writeMail(errorMessage, sended);
  }
Пример #15
0
 static SimpleEmail removeRecipient(SimpleEmail email, String emailToRemove)
     throws EmailException {
   List<String> to = Utils.noGenericTypeToStringType(email.getToAddresses()),
       cc = Utils.noGenericTypeToStringType(email.getCcAddresses()),
       bcc = Utils.noGenericTypeToStringType(email.getBccAddresses());
   if (to.contains(emailToRemove)) {
     to.remove(emailToRemove);
     email.setTo(to);
   } else if (cc.contains(emailToRemove)) {
     cc.remove(emailToRemove);
     email.setCc(cc);
   } else if (bcc.contains(emailToRemove)) {
     bcc.remove(emailToRemove);
     email.setBcc(bcc);
   }
   return email;
 }
Пример #16
0
 static void editSubjectSimple(CommandSender sender, String[] args) {
   SimpleEmail email = simpleEmail.get(sender.getName());
   email.setSubject(Utils.implode(args, " "));
   LogHelper.showInfo("emailSubjectSet", sender);
   simpleEmail.put(sender.getName(), email);
 }
Пример #17
0
  public void enviarEmail(List<String> destinos, String mensagem, String titulo)
      throws EmailException {
    SimpleEmail email = new SimpleEmail();

    email.setHostName(this.host);
    // Quando a porta utilizada não é a padrão (gmail = 465)
    email.setSmtpPort(this.porta);

    // Adicione os destinatários
    for (String destino : destinos) {
      email.addTo(destino, "", "UTF-8");
    }
    email.setSentDate(new Date());

    // Configure o seu Email do qual enviará
    email.setFrom(this.email, this.empresa.getNome());
    // Adicione um assunto
    email.setSubject(titulo);
    // Adicione a mensagem do Email
    email.setMsg(Jsoup.parse(mensagem).text());
    // Para autenticar no servidor é necessário chamar os dois métodos abaixo
    email.setTLS(true);
    email.setSSL(true);

    email.setAuthentication(this.email, this.senha);
    email.send();
  }
Пример #18
0
 static void setBouncebackSimple(CommandSender sender, String bounceback) {
   SimpleEmail email = simpleEmail.get(sender.getName());
   email.setBounceAddress(bounceback);
   LogHelper.showInfo("emailBouncebackSet", sender);
   simpleEmail.put(sender.getName(), email);
 }