本文整理匯總了Java中org.apache.commons.mail.SimpleEmail類的典型用法代碼示例。如果您正苦於以下問題:Java SimpleEmail類的具體用法?Java SimpleEmail怎麽用?Java SimpleEmail使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SimpleEmail類屬於org.apache.commons.mail包,在下文中一共展示了SimpleEmail類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendSimpleEmail
import org.apache.commons.mail.SimpleEmail; //導入依賴的package包/類
public void sendSimpleEmail(String email_to, String subject, String msg) {
SimpleEmail email = new SimpleEmail();
try {
email.setDebug(debug);
email.setHostName(smtp);
email.addTo(email_to);
email.setFrom(email_from);
email.setAuthentication(email_from, email_password);
email.setSubject(subject);
email.setMsg(msg);
email.setSSL(ssl);
email.setTLS(tls);
email.send();
} catch (EmailException e) {
System.out.println(e.getMessage());
}
}
示例2: sendEmail
import org.apache.commons.mail.SimpleEmail; //導入依賴的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);
}
}
示例3: envia
import org.apache.commons.mail.SimpleEmail; //導入依賴的package包/類
public static void envia(Registrar reg) {
try {
SimpleEmail email = new SimpleEmail();
email.setHostName("10.1.8.102");
email.addTo("[email protected]");
//email.addCc("[email protected]");
email.addCc("[email protected]");
email.addCc("[email protected]");
email.addCc("[email protected]");
//email.addCc("[email protected]");
//email.addCc("[email protected]");
email.setFrom("[email protected]");
email.setSubject("Error en tablealias");
String msg = String.format("%nServidor %s, pathInfo %s%nParametros %s ",reg.getNomServidor(), reg.getPagAccesa(), reg.getParametros());
email.setMsg("Categoria: " + reg.getCategoria() + " , Descripcion " + reg.getDescripcion() + msg + " \n Navegador:" + reg.getExplorador());
email.send();
} catch (EmailException ex1) {
ex1.printStackTrace();
}
}
示例4: sendText
import org.apache.commons.mail.SimpleEmail; //導入依賴的package包/類
@Override
public boolean sendText(String to, String subject, String content) throws EmailException {
SimpleEmail email = new SimpleEmail();
email.setHostName(host);// 設置使用發電子郵件的郵件服務器
email.addTo(to);
email.setAuthentication(user, password);
email.setFrom(from);
email.setSubject(subject);
email.setMsg(content);
if (port == 465) {
email.setSSLOnConnect(true);
email.setSslSmtpPort(Integer.toString(port)); // 若啟用,設置smtp協議的SSL端口號
}
else {
email.setSmtpPort(port);
}
email.send();
return true;
}
示例5: send
import org.apache.commons.mail.SimpleEmail; //導入依賴的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);
}
}
示例6: createEmail
import org.apache.commons.mail.SimpleEmail; //導入依賴的package包/類
protected Email createEmail() {
Email email = new SimpleEmail();
email.setHostName(config.readString(ConfigProperty.SMTP_HOST_NAME));
email.setSSLOnConnect(config.readBoolean(ConfigProperty.SMTP_USE_SSL));
if (config.readBoolean(ConfigProperty.SMTP_USE_SSL)) {
email.setSslSmtpPort(config.readString(ConfigProperty.SMTP_PORT));
} else {
email.setSmtpPort(config.readInt(ConfigProperty.SMTP_PORT));
}
if (config.readBoolean(ConfigProperty.SMTP_AUTH)) {
email.setAuthenticator(new DefaultAuthenticator(config.readString(ConfigProperty.SMTP_DEFAULT_USERNAME),
config.readString(ConfigProperty.SMTP_DEFAULT_PASSWORD)));
}
try {
email.setFrom(config.readString(ConfigProperty.EMAIL_DEFAULT_FROM),
config.readString(ConfigProperty.EMAIL_DEFAULT_FROM_NAME));
} catch (EmailException e) {
throw Exceptions.runtime(e);
}
email.setSocketConnectionTimeout(config.readInt(ConfigProperty.SMTP_CONNECTION_TIMEOUT));
email.setSocketTimeout(config.readInt(ConfigProperty.SMTP_SEND_TIMEOUT));
return email;
}
示例7: sendEmail
import org.apache.commons.mail.SimpleEmail; //導入依賴的package包/類
private void sendEmail(final String address, final String taskId, final String taskName, final Throwable cause)
throws Exception
{
Email mail = new SimpleEmail();
mail.setSubject("Task execution failure");
mail.addTo(address);
// FIXME: This should ideally render a user-configurable template
StringWriter buff = new StringWriter();
PrintWriter out = new PrintWriter(buff);
if (taskId != null) {
out.format("Task ID: %s%n", taskId);
}
if (taskName != null) {
out.format("Task Name: %s%n", taskName);
}
if (cause != null) {
out.println("Stack-trace:");
cause.printStackTrace(out);
}
mail.setMsg(buff.toString());
emailManager.get().send(mail);
}
示例8: sendMail
import org.apache.commons.mail.SimpleEmail; //導入依賴的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());
}
}
示例9: send
import org.apache.commons.mail.SimpleEmail; //導入依賴的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]");
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("[email protected]");
email.send();
return ResponseEntity.ok().build();
}
示例10: sendSimpleEmail
import org.apache.commons.mail.SimpleEmail; //導入依賴的package包/類
/**
* Test sending an {@link SimpleEmail} rather than a {@link SmtpMessage}.
*/
@Test
public void sendSimpleEmail() throws Exception {
assertThat(this.sslMailServer.getReceivedMessages().length, is(0));
SimpleEmail email = new SimpleEmail();
email.setFrom("[email protected]");
email.setSubject("subject");
email.setMsg("content");
email.addTo("[email protected]");
email.setSentDate(UtcTime.now().toDate());
SmtpSender sender = new SmtpSender(email, new SmtpClientConfig("localhost", SMTP_SSL_PORT,
new SmtpClientAuthentication(USERNAME, PASSWORD), true));
sender.call();
// check mailbox after sending
MimeMessage[] receivedMessages = this.sslMailServer.getReceivedMessages();
assertThat(receivedMessages.length, is(1));
assertThat(receivedMessages[0].getSubject(), is("subject"));
assertThat(receivedMessages[0].getSentDate(), is(FrozenTime.now().toDate()));
Object expectedContent = "content";
assertThat(GreenMailUtil.getBody(receivedMessages[0]).trim(), is(expectedContent));
}
示例11: sendNormalEmail
import org.apache.commons.mail.SimpleEmail; //導入依賴的package包/類
/**
* Send a verification email to the user's email account if exist.
*
* @param user
*/
public void sendNormalEmail(String subject, String content, String[] addresses ) {
if ( StringUtil.checkNotEmpty(subject) && StringUtil.checkNotEmpty(content) ) {
try {
String emailSmtp = GameDataManager.getInstance().getGameDataAsString(GameDataKey.EMAIL_SMTP, "mail.xinqihd.com");
SimpleEmail email = new SimpleEmail();
email.setHostName(emailSmtp);
email.setAuthenticator(new DefaultAuthenticator(EMAIL_FROM, "[email protected]"));
email.setFrom(EMAIL_FROM);
email.setSubject(subject);
email.setMsg(content);
email.setCharset("GBK");
for ( String address : addresses) {
if ( StringUtil.checkNotEmpty(address) ) {
email.addTo(address);
}
}
email.send();
} catch (EmailException e) {
logger.debug("Failed to send normal email", e);
}
}
}
示例12: send
import org.apache.commons.mail.SimpleEmail; //導入依賴的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);
}
}
示例13: createMailFor
import org.apache.commons.mail.SimpleEmail; //導入依賴的package包/類
/**
* Creates a new simple mail class and fills the subject and the body for the given person
* @param aPerson the person for whom the mail is addressed
*
* @return a mail instance
* @throws SdiException on any problem
*/
public Email createMailFor( Person<?> aPerson ) throws SdiException
{
Email email = new SimpleEmail();
try
{
email.addTo( aPerson.getEMail() );
String subject = myMailTextResolver.getResolvedSubject( aPerson );
myLog.debug( "resolved subject: " + subject);
email.setSubject( subject );
String body = myMailTextResolver.getResolvedBody( aPerson );
myLog.debug( "resolved body: " + body );
email.setMsg( body );
}
catch ( EmailException t )
{
throw new SdiException( "Problems setting up mail for " + aPerson.getEMail(),
t,
SdiException.EXIT_CODE_MAIL_ERROR );
}
return email;
}
示例14: put
import org.apache.commons.mail.SimpleEmail; //導入依賴的package包/類
@Override
public void put(final String code) throws IOException {
final Email email = new SimpleEmail();
email.setSubject(this.subject);
try {
email.setFrom("aintshy.com <[email protected]>");
email.setMsg(
String.format(
String.format("%s\n\n--\naintshy.com", this.body),
code
)
);
email.addTo(this.address);
this.postman.deliver(email);
} catch (final EmailException ex) {
throw new IOException(ex);
}
}
示例15: sendTextEmail
import org.apache.commons.mail.SimpleEmail; //導入依賴的package包/類
@Override
public void sendTextEmail(String to, String subject, String textBody) throws ServiceException {
SimpleEmail email = new SimpleEmail();
try {
setupEmail(email);
validateAddress(to);
email.addTo(to);
email.setSubject(subject);
email.setMsg(textBody);
email.send();
} catch (EmailException e) {
log.error("ZZZ.EmailException. To: " + to + " Subject: " + subject, e);
throw new ServiceException("Unable to send email.", e);
}
}