本文整理汇总了Java中org.apache.commons.mail.HtmlEmail.setMsg方法的典型用法代码示例。如果您正苦于以下问题:Java HtmlEmail.setMsg方法的具体用法?Java HtmlEmail.setMsg怎么用?Java HtmlEmail.setMsg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.mail.HtmlEmail
的用法示例。
在下文中一共展示了HtmlEmail.setMsg方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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!");
}
}
示例3: 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());
}
}
示例4: check
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
@Override
protected Result check() throws Exception {
try {
HtmlEmail testEmail = htmlEmailFactory.getHtmlEmail();
testEmail.setMsg("Testing");
testEmail.setSubject("Testing");
testEmail.setFrom("[email protected]");
final InternetAddress testToAddress = new InternetAddress("[email protected]");
ArrayList<InternetAddress> toAddresses = new ArrayList<>();
toAddresses.add(testToAddress);
testEmail.setTo(toAddresses);
testEmail.send();
return Result.healthy();
} catch (Exception e) {
return Result.unhealthy(e);
}
}
示例5: sendHtml
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
@Override
public boolean sendHtml(String to, String subject, String content) throws EmailException {
HtmlEmail email = new HtmlEmail();
email.setHostName(host);// 设置使用发电子邮件的邮件服务器
email.addTo(to);
email.setAuthentication(user, password);
email.setFrom(user);
email.setSubject(subject);
email.setMsg(content);
email.setSSLOnConnect(true);
email.setSslSmtpPort("465"); // 若启用,设置smtp协议的SSL端口号
email.send();
return true;
}
示例6: main
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
public static void main(String[] args) throws EmailException {
HtmlEmail email = new HtmlEmail();
email.setHostName("smtp.example.com");
email.setFrom("[email protected]", "From User");
email.addTo("[email protected]", "To User");
email.addTo("[email protected]", "To 2 User");
email.addCc("[email protected]", "CC User");
email.addBcc("[email protected]", "BCC User");
email.setSubject("Sample Email Subject");
email.setMsg("<p>This is body content.</p>");
email.send();
}
示例7: enviaEmailFormatoHtml
import org.apache.commons.mail.HtmlEmail; //导入方法依赖的package包/类
/**
* Envia email no formato HTML
*
* @param nomeRemetente
* @param nomeDestinatario
* @param emailRemetente
* @param emailDestinatario
* @param assunto
* @param mensagem
* @param anexo
*
* @throws EmailException
* @throws MalformedURLException
*/
public void enviaEmailFormatoHtml(String nomeRementente, String emailRemetente,
String nomeDestinatario, String emailDestinatario,
String assunto, StringBuilder mensagem,
String anexo) throws EmailException, MalformedURLException {
HtmlEmail email = new HtmlEmail();
// adiciona uma imagem ao corpo da mensagem e retorna seu id
URL url = new URL(anexo); // URL do arquivo a ser anexado
String cid = email.embed(url, "Anexos");
// configura a mensagem para o formato HTML
email.setHtmlMsg("<html>Anexos</html>");
// configure uma mensagem alternativa caso o servidor não suporte HTML
email.setTextMsg("Seu servidor de e-mail não suporta mensagem HTML");
email.setHostName("smtp.hslife.com.br"); // o servidor SMTP para envio do e-mail
email.addTo(emailDestinatario, nomeDestinatario); //destinatário
email.setFrom(emailRemetente, nomeRementente); // remetente
email.setSubject(assunto); // assunto do e-mail
email.setMsg(mensagem.toString()); //conteudo do e-mail
email.setAuthentication("[email protected]", "real123");
//email.setSmtpPort(465);
//email.setSSL(true);
//email.setTLS(true);
// envia email
email.send();
}