本文整理匯總了Java中org.springframework.mail.SimpleMailMessage.setFrom方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleMailMessage.setFrom方法的具體用法?Java SimpleMailMessage.setFrom怎麽用?Java SimpleMailMessage.setFrom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.mail.SimpleMailMessage
的用法示例。
在下文中一共展示了SimpleMailMessage.setFrom方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doRun
import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
@Override
public void doRun(Collection<HealthCheck> healthChecks) {
if (!healthChecks.isEmpty()) {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(from);
message.setSubject(subjectPrefix + " : " + healthChecks.size() + " failing checks");
message.setTo(to);
message.setText(buildMailContent(healthChecks));
JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setHost(smtpHost);
sender.setPort(smtpPort);
userName.ifPresent(name -> sender.setUsername(name));
pwd.ifPresent(pwd -> sender.setPassword(pwd));
sender.send(message);
logger.info("Notification mail sent for " + healthChecks.size() + " health checks");
}
}
示例2: sendSimpleMail
import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
/**
* 發送簡單郵件
* @param to 發送地址
* @param subject 郵件主題
* @param content 郵件內容
*/
@Override
public void sendSimpleMail(String to, String subject, String content) {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(from);
message.setTo(to);
message.setSubject(subject);
message.setText(content);
try {
mailSender.send(message);
log.info("郵件發送成功!");
} catch (Exception e) {
log.error("郵件發送失敗!");
log.error("失敗原因:{}", e);
}
}
示例3: sendMail
import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
@Override
@Async
// 異步發送郵件
public void sendMail(Comment comment, Article article) {
if (properties.getNotification()) {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(properties.getFrom());
message.setTo(properties.getTo());
message.setSubject(properties.getSubject());
String messageText = properties.getText()
.replace("author", comment.getAuthor())
.replace("title", article.getTitle())
.replace("text", comment.getText())
.replace("agent", comment.getAgent())
.replace("ip", Optional.ofNullable(comment.getIp()).orElse(""));
message.setText(messageText);
mailSender.send(message);
}
}
示例4: sendMessage
import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
public boolean sendMessage(String mailFrom, String mailTo, String subject, String mailMessage) {
SimpleMailMessage mail = new SimpleMailMessage();
if(this.isEnabled) {
try {
mail.setFrom(mailFrom);
mail.setTo(mailTo);
mail.setSubject(subject);
mail.setText(mailMessage);
mailSender.send(mail);
log.debug("Email sent : " + mail.toString());
//logService.logMail(mailTo, mailMessage, LogService.MAIL_SENT);
} catch(Exception e) {
log.error("Email failed : " + mail.toString(), e);
//logService.logMail(mailTo, mailMessage, LogService.MAIL_FAILED);
return false;
}
} else {
log.warn("sendMessage called but email is not enabled ...");
log.info("\tmethod call was : sendMessage(" + mailFrom + ", " + mailTo + ", " + subject + ", " + mailMessage + ")");
}
return true;
}
示例5: sendSimpleMail
import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
/**
* 發送文本郵件 setCc 抄送 setBcc 密送
*/
@Async("mailAsync")
public void sendSimpleMail(String to, String subject, String content) {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(from);
message.setTo(to);
message.setBcc(from);
message.setSubject(subject);
message.setText(content);
message.setSentDate(new Date());
try {
mailSender.send(message);
logger.info("簡單郵件已經發送。");
} catch (Exception e) {
logger.error("發送簡單郵件時發生異常!", e);
}
}
示例6: SendMail
import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
public SendMail() {
mailBean = new MailBean();
mailSender = new JavaMailSenderImpl();
mailSender.setPort(mailBean.getPORT());
mailSender.setHost(mailBean.getHOST());
mailSender.setUsername(mailBean.getUSERNAME());
mailSender.setPassword(mailBean.getPASSWORD());
Properties properties = new Properties();
properties.setProperty("mail.smtp.auth", "true");
mailSender.setJavaMailProperties(properties);
mailMessage = new SimpleMailMessage();
mailMessage.setFrom(mailBean.getFROM());
mailMessage.setTo(mailBean.getTO());
mailMessage.setSubject(mailBean.getSUBJECT());
GetUserInfo getUserInfo = new GetUserInfo();
mailMessage.setText("[version]:" + LoadVersion.getVersion() + "\n[javaVersion]:" + getUserInfo.getJavaVersion()
+ "\n[osName]:" + getUserInfo.getOsName() + "\n[jvmName]:" + getUserInfo.getJvmName() + "\n[address]:"
+ getUserInfo.getAddress() + "\n[hostName]:" + getUserInfo.getHostname() + "\n[startTime]:"
+ getUserInfo.getStartTime());
}
示例7: sendEmailMsg
import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
private void sendEmailMsg(String email, String content) {
logger.info("kaishi");
JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
// 設定mail server
senderImpl.setHost(mailHost);
senderImpl.setUsername(mailUserName);
senderImpl.setPassword(mailPassword);
Properties prop = new Properties();
// 將這個參數設為true,讓服務器進行認證,認證用戶名和密碼是否正確
prop.put("mail.smtp.auth", "true");
prop.put("mail.smtp.timeout", "25000");// milliseconds
senderImpl.setJavaMailProperties(prop);
// 建立郵件消息
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(email);
mailMessage.setFrom(mailSender);
mailMessage.setSubject("sam驗證碼");
mailMessage.setText(content);
// 發送郵件
senderImpl.send(mailMessage);
logger.info("successfully send mail");
}
示例8: sendAlarm
import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
public void sendAlarm(AlarmMessage data) {
SimpleMailMessage mail = new SimpleMailMessage(); // 隻發送純文本
mail.setText(data.getMessage());// 郵件內容
mail.setSubject(TITLE);// 主題
mail.setFrom(emailUsername);
String receiveKeys[] = StringUtils.split(StringUtils.replace(data.getReceiveKey(), ";", ","), ",");
List<String> address = new ArrayList<String>();
for (String receiveKey : receiveKeys) {
if (isEmailAddress(receiveKey)) {
address.add(receiveKey);
} else if (isMobileNumber(receiveKey)) {
// do nothing
}
}
if (address != null && !address.isEmpty()) {
mail.setTo(address.toArray(new String[address.size()]));
sendMail(mail);
}
}
示例9: sendmail
import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
@RequestMapping(value = "sendmail", method = RequestMethod.POST, produces = { "application/xml", "application/json" })
public ResponseEntity<Email> sendmail(@RequestBody Email email) {
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
javaMailSender.setHost(email.getHost());
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(email.getFrom());
message.setTo(email.getTo());
message.setSubject(email.getSubject());
message.setText(email.getText());
try{
javaMailSender.send(message);
email.setStatus(true);
}catch(Exception e){
email.setText(e.getMessage());
email.setStatus(false);
}
return new ResponseEntity<Email>(email, HttpStatus.OK);
}
示例10: mail
import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
@RequestMapping(value = "mail", method = RequestMethod.POST, produces = { "application/xml", "application/json" })
public ResponseEntity<Email> mail(@RequestBody Email email) {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(email.getFrom());
message.setTo(email.getTo());
message.setSubject(email.getSubject());
message.setText(email.getText());
try{
javaMailSender.send(message);
email.setStatus(true);
}catch(Exception e){
email.setText(e.getMessage());
email.setStatus(false);
}
return new ResponseEntity<Email>(email, HttpStatus.OK);
}
示例11: sendMailToAuthor
import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
private Consumer<StreamItemEntity> sendMailToAuthor(MailSender mailSender,
String markerAuthor,
String itemId,
String markerType) {
return foundItem -> {
Optional<String> authorMail = ofNullable(foundItem.getAuthor().getEmail());
if (validMailAddress(authorMail) &&
!itemAuthorEqualsMarkerAuthor(markerAuthor, foundItem)) {
SimpleMailMessage mentionMessage = new SimpleMailMessage();
mentionMessage.setFrom("[email protected]");
mentionMessage.setSubject("You got a new '" + markerType + "' on a put!");
mentionMessage.setTo(foundItem.getAuthor().getEmail());
mentionMessage.setText(new MailTemplates()
.create("markerNotification")
.replace("markerType", markerType)
.replace("markerAuthor", "@" + markerAuthor)
.replace("link", "https://putput.org/#/item/" + itemId)
.replace("content", contentPreview(foundItem))
.getText()
);
mailSender.send(mentionMessage);
}
};
}
示例12: testSendMail
import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
/**
* 測試通過SpringMailSender發送簡單的郵件
*/
@Test
public void testSendMail() {
// 建立郵件消息
SimpleMailMessage mailMessage = new SimpleMailMessage();
// 設置收件人,寄件人 用數組發送多個郵件
// String[] array = new String[] {"[email protected]","[email protected]"};
// mailMessage.setTo(array);
mailMessage.setTo(" [email protected]");
mailMessage.setFrom("[email protected]");
mailMessage.setSubject("測試簡單文本郵件發送!");
mailMessage.setText(" 測試我的簡單郵件發送機製!");
// 發送郵件
senderImpl.send(mailMessage);
System.out.println(" 郵件發送成功.. ");
}
示例13: sendMail
import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
public boolean sendMail(String to, String subject, String msg) {
try {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(from);
message.setTo(to);
message.setSubject(subject);
message.setText(msg);
javaMailSender.send(message);
return true;
} catch (Exception e) {
logger.error("sendMail: ", e);
return false;
}
}
示例14: sendMail
import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
private void sendMail(String recipient, String subject, String text) {
if (!this.enabled) {
LOG.info("Skipping sending mail to {} with body: \"{}\"", recipient, text);
return;
}
SimpleMailMessage smm = new SimpleMailMessage();
smm.setFrom(this.sendfrom);
smm.setTo(recipient);
smm.setSubject(subject);
smm.setText(text);
try {
LOG.info("send mail to {}: {}", recipient, smm);
javaMailService.send(smm);
} catch (Exception e) {
e.printStackTrace();
}
}
示例15: sendEmailTolist
import org.springframework.mail.SimpleMailMessage; //導入方法依賴的package包/類
private void sendEmailTolist(String subject,String text,String []toList) {
if(!equalsIgnoreCase(mailsenderEnable,"true")) {
log.info("Email with subject ["+subject+"] not sent as notification is not enabled.");
return;
}
try {
SimpleMailMessage smm = new SimpleMailMessage();
smm.setSubject(subject);
smm.setFrom(mailSenderFrom);
smm.setText(text);
smm.setTo(toList);
mailSender.send(smm);
log.info("Email sent with success.\nSubject:"+subject+"\n"+text);
}
catch (Exception e) {
log.error(e.getMessage(),e);
}
}