本文整理汇总了Java中org.apache.commons.mail.HtmlEmail.setCharset方法的典型用法代码示例。如果您正苦于以下问题:Java HtmlEmail.setCharset方法的具体用法?Java HtmlEmail.setCharset怎么用?Java HtmlEmail.setCharset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.mail.HtmlEmail
的用法示例。
在下文中一共展示了HtmlEmail.setCharset方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doSend
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
private void doSend(String recipient, String sender, Set<String> cc, String subject, String content,
EmailAttachment... attachments) throws EmailException {
HtmlEmail email = new HtmlEmail();
email.setCharset("utf-8");
for (EmailAttachment attachment : attachments) {
email.attach(attachment);
}
email.setHostName(HOST);
email.setSmtpPort(PORT);
email.setAuthenticator(new DefaultAuthenticator(USER, PWD));
email.setSSLOnConnect(USE_SSL);
email.setSubject(subject);
email.addTo(recipient);
email.setFrom(String.format("Exam <%s>", SYSTEM_ACCOUNT));
email.addReplyTo(sender);
for (String addr : cc) {
email.addCc(addr);
}
email.setHtmlMsg(content);
if (USE_MOCK) {
mockSending(email, content, attachments);
} else {
email.send();
}
}
示例2: send
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
public static void send(Mail mail) {
HtmlEmail email = new HtmlEmail();
try {
email.setHostName(mail.getHost());
email.setCharset(Config.UTF_8);
email.addTo(mail.getReceiver());
email.setFrom(mail.getSender(), mail.getName());
email.setAuthentication(mail.getUsername(), mail.getPassword());
email.setSubject(mail.getSubject());
email.setMsg(mail.getMessage());
email.setSmtpPort(mail.getSmtpPort());
email.send();
} catch (EmailException e) {
e.printStackTrace();
}
}
示例3: sendCommonMail
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
* 发送普通邮件
*
* @param toMailAddr
* 收信人地址
* @param subject
* email主题
* @param message
* 发送email信息
*/
public static void sendCommonMail(String toMailAddr, String subject,
String message) {
HtmlEmail hemail = new HtmlEmail();
try {
hemail.setHostName(getHost(from));
hemail.setSmtpPort(getSmtpPort(from));
hemail.setCharset(charSet);
hemail.addTo(toMailAddr);
hemail.setFrom(from, fromName);
hemail.setAuthentication(username, password);
hemail.setSubject(subject);
hemail.setMsg(message);
hemail.send();
System.out.println("email send true!");
} catch (Exception e) {
e.printStackTrace();
System.out.println("email send error!");
}
}
示例4: sendMailByApache
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
public static void sendMailByApache(String to, String title, String content) {
try {
HtmlEmail email = new HtmlEmail();
// 这里是发送服务器的名字
email.setHostName(smtpHost);
// 编码集的设置
email.setTLS(true);
email.setSSL(true);
email.setCharset("utf-8");
// 收件人的邮箱
email.addTo(to);
// 发送人的邮箱
email.setFrom(fromEmail);
// 如果需要认证信息的话,设置认证:用户名-密码。分别为发件人在邮件服务器上的注册名称和密码
email.setAuthentication(username, password);
email.setSubject(title);
// 要发送的信息
email.setMsg(content);
// 发送
email.send();
} catch (EmailException e) {
Log.i("EmailUtil", e.getMessage());
}
}
示例5: test
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
* send mail
*/
@Test
public void test() {
try {
HtmlEmail htmlEmail = new HtmlEmail();
htmlEmail.setHostName("smtp.qq.com");
htmlEmail.setFrom("[email protected]", "[email protected]");
htmlEmail.addTo("[email protected]");
htmlEmail.addCc("[email protected]", "[email protected]");
htmlEmail.setAuthentication("[email protected]", "TaylorSwift");
htmlEmail.setSubject("email example");
htmlEmail.setHtmlMsg("test apache email");
htmlEmail.setCharset("UTF-8");
htmlEmail.buildMimeMessage();
htmlEmail.sendMimeMessage();
} catch (EmailException e) {
System.out.println(e.getMessage());
}
}
示例6: sendWithHtml
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
@Override
public void sendWithHtml(String recipient, String subject, String content) throws SendMailException {
Assert.hasText(recipient);
Assert.hasText(subject);
Assert.hasText(content);
HtmlEmail email = new HtmlEmail();
email.setHostName(host);
email.setAuthenticator(new DefaultAuthenticator(loginName, loginPassword));
email.setSmtpPort(port);
email.setTLS(tls);
try {
email.setCharset("UTF-8"); // specify the charset.
email.setFrom(fromAddress, fromName);
email.setSubject(subject);
email.setHtmlMsg(content);
//email.setMsg(""); // can set plain text either
email.addTo(recipient);
email.send();
} catch (EmailException e) {
throw new SendMailException(
String.format("Failed to send mail to %s.", recipient), e);
}
}
示例7: sendHtmlEmail
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
private void sendHtmlEmail() throws MangooMailerException {
Config config = Application.getInstance(Config.class);
try {
HtmlEmail htmlEmail = new HtmlEmail();
htmlEmail.setCharset(Default.ENCODING.toString());
htmlEmail.setHostName(config.getSmtpHost());
htmlEmail.setSmtpPort(config.getSmtpPort());
htmlEmail.setAuthenticator(getDefaultAuthenticator());
htmlEmail.setSSLOnConnect(config.isSmtpSSL());
htmlEmail.setFrom(this.from);
htmlEmail.setSubject(this.subject);
htmlEmail.setHtmlMsg(render());
for (String recipient : this.recipients) {
htmlEmail.addTo(recipient);
}
for (String cc : this.ccRecipients) {
htmlEmail.addCc(cc);
}
for (String bcc : this.bccRecipients) {
htmlEmail.addBcc(bcc);
}
for (File file : this.files) {
htmlEmail.attach(file);
}
htmlEmail.send();
} catch (EmailException | MangooTemplateEngineException e) {
throw new MangooMailerException(e);
}
}
示例8: MailSender
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
* 构造方法.
* @param host
* 邮件服务器,如:"mail.heartsome.net"
* @param protocol
* 邮件协议
* @param port
* 端口号
* @param userName
* 邮箱用户名
* @param password
* 邮箱密码
* @param ssl
* 是否应用 SSL 安全协议
*/
public MailSender(String host, String protocol, int port, String userName, String password, boolean ssl) {
props = new Properties();
if (port != -1) {
this.port = port;
}
this.userName = userName;
this.password = password;
props.setProperty("mail." + protocol + ".auth", "true");
props.setProperty("mail.transport.protocol", protocol);
props.setProperty("mail.host", host);
props.setProperty("mail." + protocol + ".port", "" + this.port);
createSession();
email = new HtmlEmail();
email.setCharset("utf-8");
email.setMailSession(session);
if (ssl) {
email.setSSL(true);
}
}
示例9: initializeMail
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
* Creates a {@link HtmlEmail} object configured as per the AuthMe config
* with the given email address as recipient.
*
* @param emailAddress the email address the email is destined for
* @return the created HtmlEmail object
* @throws EmailException if the mail is invalid
*/
public HtmlEmail initializeMail(String emailAddress) throws EmailException {
String senderMail = StringUtils.isEmpty(settings.getProperty(EmailSettings.MAIL_ADDRESS))
? settings.getProperty(EmailSettings.MAIL_ACCOUNT)
: settings.getProperty(EmailSettings.MAIL_ADDRESS);
String senderName = StringUtils.isEmpty(settings.getProperty(EmailSettings.MAIL_SENDER_NAME))
? senderMail
: settings.getProperty(EmailSettings.MAIL_SENDER_NAME);
String mailPassword = settings.getProperty(EmailSettings.MAIL_PASSWORD);
int port = settings.getProperty(EmailSettings.SMTP_PORT);
HtmlEmail email = new HtmlEmail();
email.setCharset(EmailConstants.UTF_8);
email.setSmtpPort(port);
email.setHostName(settings.getProperty(EmailSettings.SMTP_HOST));
email.addTo(emailAddress);
email.setFrom(senderMail, senderName);
email.setSubject(settings.getProperty(EmailSettings.RECOVERY_MAIL_SUBJECT));
email.setAuthentication(settings.getProperty(EmailSettings.MAIL_ACCOUNT), mailPassword);
if (settings.getProperty(PluginSettings.LOG_LEVEL).includes(LogLevel.DEBUG)) {
email.setDebug(true);
}
setPropertiesForPort(email, port);
return email;
}
示例10: forgetPassword
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
* Process the forget password scenario
* @return
*/
public boolean forgetPassword(String roleName, IoSession session) {
String message = Text.text("forget.fail");
boolean result = false;
if ( StringUtil.checkNotEmpty(roleName) ) {
Account account = AccountManager.getInstance().queryAccountByName(roleName);
//User user = UserManager.getInstance().queryUserByRoleName(roleName);
//if ( user != null ) {
if ( account != null ) {
String emailAddress = account.getEmail();
if ( StringUtil.checkValidEmail(emailAddress) ) {
try {
Jedis jedis = JedisFactory.getJedisDB();
String key = StringUtil.concat(Constant.FORGET_PASS_KEY, roleName);
String tempPassword = jedis.get(key);
if ( tempPassword != null ) {
message = Text.text("forget.ok");
result = true;
} else {
String emailSmtp = GameDataManager.getInstance().getGameDataAsString(GameDataKey.EMAIL_SMTP, "xinqihd.com");
HtmlEmail email = new HtmlEmail();
email.setHostName(emailSmtp);
email.setAuthenticator(new DefaultAuthenticator(EMAIL_FROM, "[email protected]"));
email.setFrom(EMAIL_FROM);
String subject = Text.text("forget.subject");
tempPassword = String.valueOf(System.currentTimeMillis()%10000);
String displayRoleName = UserManager.getDisplayRoleName(account.getUserName());
String content = Text.text("forget.content", displayRoleName, tempPassword);
email.setSubject(subject);
email.setHtmlMsg(content);
email.setCharset("GBK");
email.addTo(emailAddress);
email.send();
jedis.set(key, tempPassword);
jedis.expire(key, Constant.HALF_HOUR_SECONDS);
message = Text.text("forget.ok");
result = true;
}
} catch (EmailException e) {
logger.error("Failed to send email to user's email: {}", emailAddress);
logger.debug("EmailException", e);
}
} else {
message = Text.text("forget.noemail");
}
//StatClient.getIntance().sendDataToStatServer(user, StatAction.ForgetPassword, emailAddress, result);
} else {
message = Text.text("forget.nouser");
}
} else {
message = Text.text("forget.noname");
}
BseSysMessage.Builder builder = BseSysMessage.newBuilder();
builder.setMessage(message);
builder.setSeconds(5000);
builder.setAction(XinqiSysMessage.Action.NOOP);
builder.setType(XinqiSysMessage.Type.NORMAL);
BseSysMessage sysMessage = builder.build();
XinqiMessage response = new XinqiMessage();
response.payload = sysMessage;
session.write(response);
return result;
}
示例11: getPasswrod
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
* @Title: getpassword
* @Description: TODO(会员忘记密码,通过邮箱获取密码)
* @param @param member
* @param @param session
* @param @return设定文件
* @return Object 返回类型
* @throws
*
*/
@RequestMapping(value = "/getPasswrod.htm", method = RequestMethod.GET)
public Object getPasswrod(@Valid
String useremal, HttpServletRequest request, HttpSession session) {
JqReturnJson returnResult = new JqReturnJson();// 构建返回结果,默认结果为false
Member member = new Member();
if (useremal == null) {
returnResult.setMsg("邮箱不能为空");
// 邮箱不存在,就返回这个消息给前台
session.setAttribute("emailStatus", "false");
return "retrievePassword/retrievePasswordEmail";
}
member = memberService.retrieveEmail(useremal);
if (member == null) {
returnResult.setMsg("邮箱不存在");
// 邮箱不存在,就返回这个消息给前台
session.setAttribute("emailStatus", "false");
return "retrievePassword/retrievePasswordEmail";
}
returnResult.setSuccess(true);
ModelAndView mav = new ModelAndView("retrievePassword/sendMail");
// 创建一个临时ID
String retrieveId = "" + Math.random() * Math.random();
/**
* 得到web系统url路径的方法
* */
// 得到web的url路径:http://localhost:8080/ssh1/
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
// 邮件发送成功后,用户点在邮箱中点击这个链接回到设置新密码网站。
String url = basePath + "mailBackPassword.htm?retrieveId=" + retrieveId;
// 将验证邮箱链接后面的registerId存到session中
session.setAttribute(retrieveId, retrieveId);
session.setAttribute("userEmail", useremal);// 把用户邮箱保存起来
// 把用户邮箱存起来
// 设置session的有效时间,为10分钟,10分钟内没有点击链接的话,设置密码将失败
session.setMaxInactiveInterval(600);
// 基于org.apache.commons.mail,封装好的mail,发邮件流程比较简单,比原生态mail简单。
HtmlEmail email = new HtmlEmail();
email.setHostName("smtp.qq.com");// QQ郵箱服務器
// email.setHostName("smtp.163.com");// 163郵箱服務器
// email.setHostName("smtp.gmail.com");// gmail郵箱服務器
email.setSmtpPort(465);// 设置端口号
email.setAuthenticator(new DefaultAuthenticator("[email protected]", "zx5304960"));// 用[email protected]这个邮箱发送验证邮件的
email.setTLS(true);// tls要设置为true,没有设置会报错。
email.setSSL(true);// ssl要设置为true,没有设置会报错。
try {
email.setFrom("[email protected]", "冰川网贷管理员", "UTF-8");
// email.setFrom("[email protected]", "[email protected]",
// "UTF-8");
// email.setFrom("[email protected]", "[email protected]", "UTF-8");
} catch (EmailException e1) {
e1.printStackTrace();
}
email.setCharset("UTF-8");// 没有设置会乱码。
try {
email.setSubject("冰川网贷密码找回");// 设置邮件名称
email.setHtmlMsg("尊敬的会员:<font color='blue'>" + member.getMemberName() + "</font>,请点击<a href='" + url + "'>" + url + "</a>完成新密码设置!");// 设置邮件内容
email.addTo(useremal);// 给会员发邮件
email.send();// 邮件发送
} catch (EmailException e) {
throw new RuntimeException(e);
}
return mav;
}
示例12: sendVerifyEmail
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
* Send a verification email to the user's email account if exist.
*
* @param user
*/
public void sendVerifyEmail(Account account, IoSession session) {
if ( StringUtil.checkNotEmpty(account.getEmail()) ) {
if ( StringUtil.checkValidEmail(account.getEmail()) ) {
try {
String emailSmtp = GameDataManager.getInstance().getGameDataAsString(GameDataKey.EMAIL_SMTP, "mail.xinqihd.com");
HtmlEmail email = new HtmlEmail();
email.setHostName(emailSmtp);
email.setAuthenticator(new DefaultAuthenticator(EMAIL_FROM, "[email protected]"));
email.setFrom(EMAIL_FROM);
String subject = Text.text("email.subject");
String http = StringUtil.concat(GlobalConfig.getInstance().getStringProperty("runtime.httpserverid"),
Constant.PATH_SEP, "verifyemail", Constant.QUESTION, account.get_id().toString());
String content = Text.text("email.content", account.getUserName(), http);
email.setSubject(subject);
email.setHtmlMsg(content);
email.setCharset("GBK");
email.addTo(account.getEmail());
email.send();
SysMessageManager.getInstance().sendClientInfoRawMessage(session, Text.text("email.sent"),
Action.NOOP, Type.NORMAL);
} catch (EmailException e) {
logger.debug("Failed to send verify email to user {}'s address:{}", account.getUserName(), account.getEmail());
}
} else {
//email not valid
SysMessageManager.getInstance().sendClientInfoRawMessage(session, "email.invalid", Action.NOOP, Type.NORMAL);
}
} else {
//no email at all
SysMessageManager.getInstance().sendClientInfoRawMessage(session, "email.no", Action.NOOP, Type.NORMAL);
}
}