本文整理了Java中org.apache.commons.mail.Email.setFrom()
方法的一些代码示例,展示了Email.setFrom()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Email.setFrom()
方法的具体详情如下:
包路径:org.apache.commons.mail.Email
类名称:Email
方法名:setFrom
[英]Set the FROM field of the email to use the specified address. The email address will also be used as the personal name. The name will be encoded by the charset of #setCharset(java.lang.String). If it is not set, it will be encoded using the Java platform's default charset (UTF-16) if it contains non-ASCII characters; otherwise, it is used as is.
[中]将电子邮件的“发件人”字段设置为使用指定的地址。电子邮件地址也将用作个人姓名。名称将由#setCharset(java.lang.String)的字符集编码。如果未设置,则如果包含非ASCII字符,将使用Java平台的默认字符集(UTF-16)对其进行编码;否则,按原样使用。
代码示例来源:origin: Activiti/Activiti
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);
}
}
代码示例来源:origin: apache/kylin
email.setFrom(sender);
email.setSubject(subject);
email.setCharset("UTF-8");
代码示例来源:origin: apache/incubator-gobblin
email.setSmtpPort(state.getPropAsInt(ConfigurationKeys.EMAIL_SMTP_PORT_KEY));
email.setFrom(state.getProp(ConfigurationKeys.EMAIL_FROM_KEY));
if (state.contains(ConfigurationKeys.EMAIL_USER_KEY) && state.contains(ConfigurationKeys.EMAIL_PASSWORD_KEY)) {
email.setAuthentication(state.getProp(ConfigurationKeys.EMAIL_USER_KEY),
代码示例来源:origin: Graylog2/graylog2-server
email.setStartTLSEnabled(configuration.isUseTls());
if (pluginConfig != null && !isNullOrEmpty(pluginConfig.getString("sender"))) {
email.setFrom(pluginConfig.getString("sender"));
} else {
email.setFrom(configuration.getFromEmail());
代码示例来源:origin: jooby-project/jooby
email.setCharset(mail.getString("charset"));
ifset("debug", p -> email.setDebug(mail.getBoolean(p)));
ifset("from", p -> email.setFrom(mail.getString(p)));
ifset("hostName", p -> email.setHostName(mail.getString(p)));
ifset("msg", p -> {
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Set the FROM field of the email to use the specified address. The email
* address will also be used as the personal name.
* The name will be encoded by the charset of {@link #setCharset(java.lang.String) setCharset()}.
* If it is not set, it will be encoded using
* the Java platform's default charset (UTF-16) if it contains
* non-ASCII characters; otherwise, it is used as is.
*
* @param email A String.
* @return An Email.
* @throws EmailException Indicates an invalid email address.
* @since 1.0
*/
public Email setFrom(final String email)
throws EmailException
{
return setFrom(email, null);
}
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Set the FROM field of the email to use the specified address and the
* specified personal name.
* The name will be encoded by the charset of {@link #setCharset(java.lang.String) setCharset()}.
* If it is not set, it will be encoded using
* the Java platform's default charset (UTF-16) if it contains
* non-ASCII characters; otherwise, it is used as is.
*
* @param email A String.
* @param name A String.
* @return An Email.
* @throws EmailException Indicates an invalid email address.
* @since 1.0
*/
public Email setFrom(final String email, final String name)
throws EmailException
{
return setFrom(email, name, this.charset);
}
代码示例来源:origin: Dreampie/Resty
private static void configEmail(String subject, Email email, String... recipients) throws EmailException {
if (recipients == null)
throw new EmailException("Recipients not found.");
Mail mail = MailPlugin.getMail();
email.setCharset(mail.getCharset());
email.setSocketTimeout(mail.getTimeout());
email.setSocketConnectionTimeout(mail.getConnectout());
email.setHostName(mail.getHost());
if (!mail.getSslport().isEmpty())
email.setSslSmtpPort(mail.getSslport());
if (!mail.getPort().isEmpty())
email.setSmtpPort(Integer.parseInt(mail.getPort()));
email.setSSLOnConnect(mail.isSsl());
email.setStartTLSEnabled(mail.isTls());
email.setDebug(mail.isDebug());
email.setAuthentication(mail.getUser(), mail.getPassword());
email.setFrom(mail.getFrom(), mail.getName());
email.setSubject(subject);
email.addTo(recipients);
}
代码示例来源:origin: camunda/camunda-bpm-platform
protected void setFrom(Email email, String from) {
String fromAddress = null;
if (from != null) {
fromAddress = from;
} else { // use default configured from address in process engine config
fromAddress = Context.getProcessEngineConfiguration().getMailServerDefaultFrom();
}
try {
email.setFrom(fromAddress);
} catch (EmailException e) {
throw LOG.addSenderException(from, e);
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
protected void setFrom(Email email, String from) {
String fromAddress = null;
if (from != null) {
fromAddress = from;
} else { // use default configured from address in process engine config
fromAddress = Context.getProcessEngineConfiguration().getMailServerDefaultFrom();
}
try {
email.setFrom(fromAddress);
} catch (EmailException e) {
throw LOG.addSenderException(from, e);
}
}
代码示例来源:origin: KylinOLAP/Kylin
email.setFrom(sender);
email.setSubject(subject);
email.setCharset("UTF-8");
代码示例来源:origin: javahongxi/whatsmars
public void sendEmail(Email email) throws Exception {
email.setAuthentication(username, password);
email.setCharset(DEFAULT_CHARSET);
email.setFrom(fromAddress);
email.setSSLOnConnect(sslOn);
email.setHostName(hostName);
email.setSmtpPort(smtpPort);
email.send();
}
代码示例来源:origin: stackoverflow.com
Email email = new SimpleEmail();
String authuser = "...@gmail.com";
String authpwd = "xxxx";
email.setSmtpPort(587);
email.setAuthenticator(new DefaultAuthenticator(authuser, authpwd));
email.setDebug(true);
email.setHostName("smtp.gmail.com");
email.getMailSession().getProperties().put("mail.smtps.auth", "true");
email.getMailSession().getProperties().put("mail.debug", "true");
email.getMailSession().getProperties().put("mail.smtps.port", "587");
email.getMailSession().getProperties().put("mail.smtps.socketFactory.port", "587");
email.getMailSession().getProperties().put("mail.smtps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
email.getMailSession().getProperties().put("mail.smtps.socketFactory.fallback", "false");
email.getMailSession().getProperties().put("mail.smtp.starttls.enable", "true");
email.setFrom("........@gmail.com", "SenderName");
email.setSubject("TestMail");
email.setMsg("This is a test mail?");
email.addTo("xxxx@gmail.com", "ToName");
email.setTLS(true);
email.send();
代码示例来源:origin: stackoverflow.com
Email email = new SimpleEmail();
email.setHostName("smtp.gmail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("username", "password"));
email.setSSLOnConnect(true);
email.setFrom("user@gmail.com");
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("foo@bar.com");
email.send();
代码示例来源:origin: stackoverflow.com
Email email = new SimpleEmail();
email.setHostName("smtp.gmail.com");
email.setSmtpPort(587);
email.setAuthenticator(new DefaultAuthenticator("username", "password"));
email.setStartTLSEnabled(true);
email.setFrom("user@gmail.com");
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("foo@bar.com");
email.send();
代码示例来源:origin: stackoverflow.com
Email email = new SimpleEmail();
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("username", "password"));
email.setSSLOnConnect(true);
email.setFrom("user@gmail.com");
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("foo@bar.com");
email.send();
代码示例来源:origin: stackoverflow.com
Email email = new SimpleEmail();
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("username", "password"));
email.setSSLOnConnect(true);
email.setFrom("user@gmail.com");
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("foo@bar.com");
email.send();
代码示例来源:origin: stackoverflow.com
Email email = new SimpleEmail();
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("username", "password"));
email.setSSLOnConnect(true);
email.setFrom("user@gmail.com");
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("foo@bar.com");
email.send();
代码示例来源:origin: biezhi/java-library-examples
public static void main(String[] args) throws EmailException {
Email email = new SimpleEmail();
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("username", "password"));
email.setSSLOnConnect(true);
email.setFrom("user@gmail.com");
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("foo@bar.com");
email.send();
}
}
代码示例来源:origin: stackoverflow.com
Email email = new SimpleEmail();
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("username", "password"));
email.setSSLOnConnect(true);
email.setFrom("user@gmail.com");
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("foo@bar.com");
email.send();
内容来源于网络,如有侵权,请联系作者删除!