当前位置: 首页>>代码示例>>Java>>正文


Java Email.setFrom方法代码示例

本文整理汇总了Java中org.apache.commons.mail.Email.setFrom方法的典型用法代码示例。如果您正苦于以下问题:Java Email.setFrom方法的具体用法?Java Email.setFrom怎么用?Java Email.setFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.mail.Email的用法示例。


在下文中一共展示了Email.setFrom方法的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: setFrom

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
protected void setFrom(Email email, String from, String tenantId) {
    String fromAddress = null;

    if (from != null) {
        fromAddress = from;
    } else { // use default configured from address in process engine config
        if (tenantId != null && tenantId.length() > 0) {
            Map<String, MailServerInfo> mailServers = CommandContextUtil.getProcessEngineConfiguration().getMailServers();
            if (mailServers != null && mailServers.containsKey(tenantId)) {
                MailServerInfo mailServerInfo = mailServers.get(tenantId);
                fromAddress = mailServerInfo.getMailServerDefaultFrom();
            }
        }

        if (fromAddress == null) {
            fromAddress = CommandContextUtil.getProcessEngineConfiguration().getMailServerDefaultFrom();
        }
    }

    try {
        email.setFrom(fromAddress);
    } catch (EmailException e) {
        throw new FlowableException("Could not set " + from + " as from address in email", e);
    }
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:26,代码来源:MailActivityBehavior.java

示例4: setFrom

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
protected void setFrom(Email email, String from, String tenantId) {
    String fromAddress = null;

    if (from != null) {
        fromAddress = from;
    } else { // use default configured from address in process engine config
        if (tenantId != null && tenantId.length() > 0) {
            Map<String, MailServerInfo> mailServers = Context.getProcessEngineConfiguration().getMailServers();
            if (mailServers != null && mailServers.containsKey(tenantId)) {
                MailServerInfo mailServerInfo = mailServers.get(tenantId);
                fromAddress = mailServerInfo.getMailServerDefaultFrom();
            }
        }

        if (fromAddress == null) {
            fromAddress = Context.getProcessEngineConfiguration().getMailServerDefaultFrom();
        }
    }

    try {
        email.setFrom(fromAddress);
    } catch (EmailException e) {
        throw new ActivitiException("Could not set " + from + " as from address in email", e);
    }
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:26,代码来源:MailActivityBehavior.java

示例5: 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

示例6: createEmail

import org.apache.commons.mail.Email; //导入方法依赖的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;
}
 
开发者ID:dmart28,项目名称:gcplot,代码行数:24,代码来源:SMTPMailProvider.java

示例7: 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

示例8: 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

示例9: 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

示例10: buildMessage

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
/**
 *
 */
public static Email buildMessage(Email email) throws EmailException {

    String from = GojaConfig.getProperty("mail.smtp.from");
    if (email.getFromAddress() == null && !StringUtils.isEmpty(from)) {
        email.setFrom(from);
    } else if (email.getFromAddress() == null) {
        throw new MailException("Please define a 'from' email address", new NullPointerException());
    }
    if ((email.getToAddresses() == null || email.getToAddresses().size() == 0) &&
            (email.getCcAddresses() == null || email.getCcAddresses().size() == 0) &&
            (email.getBccAddresses() == null || email.getBccAddresses().size() == 0)) {
        throw new MailException("Please define a recipient email address",
                new NullPointerException());
    }
    if (email.getSubject() == null) {
        throw new MailException("Please define a subject", new NullPointerException());
    }
    if (email.getReplyToAddresses() == null || email.getReplyToAddresses().size() == 0) {
        email.addReplyTo(email.getFromAddress().getAddress());
    }

    return email;
}
 
开发者ID:GojaFramework,项目名称:goja,代码行数:27,代码来源:EMail.java

示例11: 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

示例12: 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]");
  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

示例13: 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

示例14: put

import org.apache.commons.mail.Email; //导入方法依赖的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);
    }
}
 
开发者ID:aintshy,项目名称:hub,代码行数:19,代码来源:SmtpPocket.java

示例15: setupEmail

import org.apache.commons.mail.Email; //导入方法依赖的package包/类
private void setupEmail(Email email) throws EmailException {
	email.setHostName(getHostName());
	email.setSslSmtpPort(getSmtpPort());
	email.setFrom(getReplyAddress(), getReplyName());

	if (StringUtils.isNotBlank(useSsl)) {
		email.setSSL(Boolean.valueOf(getUseSsl()));
		email.setSslSmtpPort(getSslPort());
	}

	if (StringUtils.isNotBlank(useTls)) {
		email.setTLS(Boolean.valueOf(getUseTls()));
	}

	// use authentication if configured
	if (StringUtils.isNotBlank(getAuthenticationUserName())) {
		email.setAuthenticator(new DefaultAuthenticator(getAuthenticationUserName(), getAuthenticationPassword()));
	}
}
 
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:20,代码来源:EmailServiceImpl.java


注:本文中的org.apache.commons.mail.Email.setFrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。