當前位置: 首頁>>代碼示例>>Java>>正文


Java Email.send方法代碼示例

本文整理匯總了Java中org.apache.commons.mail.Email.send方法的典型用法代碼示例。如果您正苦於以下問題:Java Email.send方法的具體用法?Java Email.send怎麽用?Java Email.send使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.mail.Email的用法示例。


在下文中一共展示了Email.send方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendEmail

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
public void sendEmail(final EmailData emailData) {
  try {
    Email email = new SimpleEmail();
    email.setHostName(smtpServer);
    email.setSmtpPort(smtpPort);
    email.setAuthenticator(new DefaultAuthenticator(username, password));
    email.setSSLOnConnect(secure);
    email.setFrom(emailData.getAddressFrom());
    email.setSubject(emailData.getSubject());
    email.setMsg(emailData.getMessageContent());
    email.addTo(emailData.getAddressTo());
    email.send();
  } catch (org.apache.commons.mail.EmailException e) {
    throw new EmailException(e);
  }
}
 
開發者ID:Cognifide,項目名稱:bobcat,代碼行數:17,代碼來源:EmailSender.java

示例2: send

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
protected void send(String mailAddress, String title, String content) {
    if (StringUtils.isBlank(mailAddress)) {
        return;
    }

    try {
        Email email = new HtmlEmail();
        email.setHostName(hostname);
        email.setAuthenticator(new DefaultAuthenticator(username, password));
        email.setSmtpPort(port);
        email.setFrom(from, fromname);
        email.setSubject(title);
        email.setMsg(content);
        email.addTo(mailAddress.split(mailAddressEndSeparator));
        email.send();
    } catch (Exception e) {
        logger.error("Send Mail Error", e);
    }
}
 
開發者ID:XiaoMi,項目名稱:shepher,代碼行數:20,代碼來源:GeneralMailSender.java

示例3: send

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
@Override
public void send(String absender, String empfaenger, String betreff, String text) {
	try {
		final Email email = new SimpleEmail();
		email.setHostName(mailhost);
		email.setSmtpPort(mailport);
		email.setFrom(absender);
		email.setSubject(betreff);
		email.setMsg(text);
		email.addTo(empfaenger);
		email.send();
		log.info("mail sent to: " + empfaenger);
	} catch (final EmailException e) {
		log.error(e.getMessage(), e);
	}
}
 
開發者ID:SchweizerischeBundesbahnen,項目名稱:releasetrain,代碼行數:17,代碼來源:SMTPUtilImpl.java

示例4: sendEmail

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
private void sendEmail() throws EmailException, UnknownHostException {

		List<String> addresses =
				Lists.newArrayList(Splitter.on(',')
						.omitEmptyStrings()
						.trimResults()
						.split(ADMIN_EMAIL.getAdmins()));
		logger.info("Sending email to {}", addresses.toString());


		Email email = new HtmlEmail();
		email.setHostName(ADMIN_EMAIL.getHost());
		email.setSocketTimeout(30000); // 30 seconds
		email.setSocketConnectionTimeout(30000); // 30 seconds
		for (String address : addresses) {
			email.addTo(address);
		}
		email.setFrom(SorcererInjector.get().getModule().getName() + "@" +
				InetAddress.getLocalHost().getHostName());
		email.setSubject(title);
		email.setMsg(body);
		email.send();

	}
 
開發者ID:turn,項目名稱:sorcerer,代碼行數:25,代碼來源:Emailer.java

示例5: sendMail

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
private static void sendMail(String title, String message, String emailaddy) {
    try {
        Email email = new SimpleEmail();
        email.setHostName(p.getProperty("mailserver.host"));
        email.setSmtpPort(Integer.parseInt(p.getProperty("mailserver.port")));
        if(p.getProperty("mailserver.useauth").equals("true"))
        {
            email.setAuthentication(p.getProperty("mailserver.user"), p.getProperty("mailserver.pass"));
        }
        if(p.getProperty("mailserver.usessl").equals("true"))
        {
            email.setSSLOnConnect(true);
        }
        else
        {
            email.setSSLOnConnect(false);
        }
        email.setFrom(p.getProperty("mailserver.from"));
        email.setSubject("[MuninMX] " + title);
        email.setMsg(message);
        email.addTo(emailaddy);
        email.send();
    } catch (Exception ex) {
        logger.warn("Unable to send Mail: " + ex.getLocalizedMessage());
    }
}
 
開發者ID:flyersa,項目名稱:MuninMX,代碼行數:27,代碼來源:Methods.java

示例6: send

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
void send(Mail mail) {
  if(logger.isTraceEnabled()) {
    logger.trace("New mail to send - {}", mail.subject);
  }

  Email email = smtp.emptyEmail();
  email.setSubject(mail.subject);
  try {
    email.setFrom(mail.from);
    email.setTo(Arrays.asList(new InternetAddress(mail.to)));
    email.setMsg(mail.body);

    if(logger.isDebugEnabled()) {
      logger.debug("Send mail {}", mail.subject);
    }

    email.send();
  } catch (EmailException | AddressException e) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:vvergnolle,項目名稱:vas,代碼行數:22,代碼來源:MailWorker.java

示例7: sendEmail

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
public static String sendEmail(
		String fromMail,
		String fromName,
		String to,
		String subject,
		String body,
		boolean html) throws EmailException {
	Email email;
	if (html) {
		email = EmailUtils.getHtmlEmail();
	} else {
		email = EmailUtils.getSimpleEmail();
	}
	String msgId = null;
	
	email.setFrom(fromMail, fromName);
	email.addTo(to);
	email.setSubject(subject);
	email.setMsg(body);

	msgId = email.send();
	LOG.infof("Sent e-mail with ID: %s", msgId);
	
	return msgId;
}
 
開發者ID:progolden,項目名稱:vraptor-boilerplate,代碼行數:26,代碼來源:EmailUtils.java

示例8: send

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
@RequestMapping("/send")
public HttpEntity<Void> send() throws EmailException {

  // An unlucky fool hardcoded some smtp code here.
  Email email = new SimpleEmail();
  email.setHostName("localhost");
  email.setSmtpPort(3025);
  email.setAuthenticator(new DefaultAuthenticator("username", "password"));
  email.setFrom("[email protected]uth.co.uk");
  email.setSubject("TestMail");
  email.setMsg("This is a test mail ... :-)");
  email.addTo("[email protected]");
  email.send();

  return ResponseEntity.ok().build();
}
 
開發者ID:AndreasKl,項目名稱:java-classic-playground,代碼行數:17,代碼來源:SendMailController.java

示例9: send

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
/**
 * Sends the given {@link Email} using the given send settings.
 *
 * @param email
 *            {@link Email} to be sent.
 * @param settings
 *            SMTP send settings.
 * @throws SmtpSenderException
 */
private void send(Email email, SmtpClientConfig settings) throws SmtpSenderException {
    checkNotNull(email, "email message cannot be null");
    if (LOG.isTraceEnabled()) {
        LOG.trace("sending email to {} with server settings {}", email.getToAddresses(), settings);
    }

    applySendSettings(email, settings);
    try {
        email.send();
    } catch (EmailException e) {
        throw new SmtpSenderException(String.format("failed to send email: %s", e.getMessage()), e);
    }

    if (LOG.isTraceEnabled()) {
        LOG.trace("email sent to " + email.getToAddresses());
    }
}
 
開發者ID:elastisys,項目名稱:scale.commons,代碼行數:27,代碼來源:SmtpSender.java

示例10: send

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
@NotInServiceMenu
@Named("Enviar Correo")
public String send(final Cliente unCliente, final Oferta unaOferta) {

	try {
		Email email = new SimpleEmail();
		email.setHostName("smtp.gmail.com");
		email.setSmtpPort(465);
		email.setAuthentication("[email protected]", "modica1234");
		email.setSSLOnConnect(true);
		email.setFrom("[email protected]", "Resto Tesis");
		email.setSubject("Ofertas para esta Semana!");
		email.setMsg(printing.ofertaToText(unaOferta));			
		email.addTo(unCliente.getCorreo());
		return email.send();
	} catch (EmailException e) {
		throw new servicio.correo.CorreoException(e.getMessage(), e);
	}
}
 
開發者ID:resto-tesis,項目名稱:resto-tesis,代碼行數:20,代碼來源:CorreoServicio.java

示例11: sendMail

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
public void sendMail(Mail mail)
        throws IOException {
    Email email = mail.getMail();

    try {
        setEncryption(email);

        email.setHostName(host);
        email.setSmtpPort(port);
        email.setCharset("UTF-8");
        email.send();
    } catch (EmailException e) {
        if (Utility.throwableContainsMessageContaining(e, "no object DCH")) {
            throw new UnhandledException("\"no object DCH\" Likely cause: the activation jar-file cannot see the mail jar-file. Different ClassLoaders?", e);
        } else {
            throw new UnhandledException(e);
        }
    }
}
 
開發者ID:imCodePartnerAB,項目名稱:imcms,代碼行數:20,代碼來源:SMTP.java

示例12: send

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
@Override
protected void send(EmailConfigDTO configDTO, ToSend message) {

    try {
        Email email = new SimpleEmail();
        email.setHostName(server);
        email.setSmtpPort(port);
        email.setAuthenticator(new DefaultAuthenticator(login, password));
        email.setSSLOnConnect(true);
        email.setFrom(from);
        email.setSubject(message.getSubject());
        email.setMsg(message.getBody());
        email.addTo(configDTO.getRecipient());
        email.send();

    } catch (EmailException ex) {
        LOGGER.error("Send E-mail exception.", ex);
    }
}
 
開發者ID:eliogrin,項目名稱:CISEN,代碼行數:20,代碼來源:EmailMessenger.java

示例13: sendMail

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
@Override
public void sendMail(String recipient, String subject, String content) throws FablabException {
	try {
		Email email = new SimpleEmail();
		email.setHostName("localhost");
		email.setSmtpPort(25);
		email.setAuthenticator(new DefaultAuthenticator("test", "test"));
		email.setFrom("[email protected]");
		email.setSubject(subject);
		email.setMsg(content);
		email.addTo(recipient);
		email.send();
	} catch (EmailException ex) {
		LOG.error("Canont send mail ", ex);
	}
}
 
開發者ID:romainGuiet,項目名稱:fablab-web,代碼行數:17,代碼來源:MailServiceImpl.java

示例14: send

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
public boolean send(String to, String subject, String tpl, Context ctx) {
	Email email = new SimpleEmail();
	email.setHostName(config.get("mail.host"));
	email.setAuthenticator(new DefaultAuthenticator(config.get("mail.user"), config.get("mail.passwd")));
	if (config.getInt("mail.ssl", 0) == 1) {
		email.setSSLOnConnect(true);
		email.setSmtpPort(config.getInt("mail.port", 465));
	} else {
		email.setSmtpPort(config.getInt("mail.port", 25));
	}
	try {
		email.setFrom(config.get("mail.from"));
		email.setSubject("["+config.get("mail.suject.prefix", "Test") + "] " + subject);
		email.setMsg(Segments.create(tpl).render(ctx).toString());
		email.addTo(to);
		email.send();
		return true;
	} catch (EmailException e) {
		log.info("Send email fail", e);
		return false;
	}
}
 
開發者ID:amdiaosi,項目名稱:nutzWx,代碼行數:23,代碼來源:MailServiceImpl.java

示例15: sendEmail

import org.apache.commons.mail.Email; //導入方法依賴的package包/類
/**
 * Send email message for external notifications
 *
 * @param subject Email Subject Text
 * @param message Email Message Text
 */
private static void sendEmail(String subject, String message){

    try{
        if(EMAIL_ENABLED && EMAIL_FROM != null && !EMAIL_FROM.isEmpty()){
            Email email = new SimpleEmail();
            email.setHostName(EMAIL_SERVER);
            email.setSmtpPort(EMAIL_PORT);
            email.setFrom(EMAIL_FROM);
            email.addTo(EMAIL_TO);
            email.setSubject(subject);
            email.setMsg(message);
            email.send();
        }
    }
    catch(Exception ex){
        ex.printStackTrace();
    }
}
 
開發者ID:savagehomeautomation,項目名稱:pi4j-javaone-demos,代碼行數:25,代碼來源:AccessControl.java


注:本文中的org.apache.commons.mail.Email.send方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。