本文整理汇总了Java中org.springframework.mail.SimpleMailMessage.setText方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleMailMessage.setText方法的具体用法?Java SimpleMailMessage.setText怎么用?Java SimpleMailMessage.setText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.mail.SimpleMailMessage
的用法示例。
在下文中一共展示了SimpleMailMessage.setText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEmails
import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
@Override
public List<SimpleMailMessage> getEmails()
throws MessagingException, IOException, NamingException {
Session emailSession = null;
Store store = null;
Folder emailFolder = null;
List<SimpleMailMessage> receivedEmails = new ArrayList<SimpleMailMessage>();
try {
if (!StringUtils.isEmpty(mailSettings.getJndiName())) {
InitialContext ic = new InitialContext();
emailSession = (Session) ic.lookup(mailSettings.getJndiName());
store = emailSession.getStore();
store.connect();
}
else {
// Set connection properties
Properties properties = new Properties();
String prefix = "mail.".concat(mailSettings.getProtocol());
properties.put(String.format("%s.host", prefix), mailSettings.getHost());
properties.put(String.format("%s.port", prefix), mailSettings.getPort());
properties.put("mail.store.protocol", mailSettings.getProtocol());
properties.put(String.format("%s.starttls.enable", prefix), mailSettings.getStarttlsEnabled());
// Create the session and the object Store to get the emails
emailSession = Session.getDefaultInstance(properties);
store = emailSession.getStore();
store.connect(mailSettings.getUsername(), mailSettings.getPassword());
}
// Get the folder that contains the emails and open it
emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_ONLY);
// Get emails that haven't been read
Message[] messagesReceived = emailFolder.getMessages();
for (Message message : messagesReceived) {
Object content = message.getContent();
String body = null;
if (content instanceof Multipart) {
Multipart multipart = (Multipart) content;
BodyPart bodyPart = multipart.getBodyPart(0);
if (bodyPart != null) {
body = bodyPart.getContent().toString();
}
}
else if (content instanceof String) {
body = (String) content;
}
SimpleMailMessage email = new SimpleMailMessage();
email.setSubject(message.getSubject());
email.setText(body);
email.setFrom(message.getFrom()[0].toString());
email.setSentDate(message.getSentDate());
receivedEmails.add(email);
}
}
finally {
// Close objects Folder and Store
if (emailFolder != null && emailFolder.isOpen()) {
emailFolder.close(false);
}
if (store != null && store.isConnected()) {
store.close();
}
}
return receivedEmails;
}
示例2: sendMessageCc
import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
public boolean sendMessageCc(String mailFrom, String mailTo,String Cc, String subject, String mailMessage) {
SimpleMailMessage mail = new SimpleMailMessage();
if(this.isEnabled) {
try {
mail.setFrom(mailFrom);
mail.setTo(mailTo);
mail.setSubject(subject);
mail.setText(mailMessage);
mail.setCc(Cc);
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 +", "+Cc+ ", " + subject + ", " + mailMessage + ")");
}
return true;
}
示例3: confirmRegistration
import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
private void confirmRegistration(OnRegistrationCompleteEvent event) {
User user = event.getUser();
String token = UUID.randomUUID().toString();
userService.createVerificationToken(user, token);
String recipientAddress = user.getEmail();
String subject = "AntiSocial Registration Confirmation";
String confirmationUrl = event.getAppUrl() + "/registrationConfirm?token=" + token;
String message = "Hi "+user.getName()+" ,\n\nPlease confirm your e-mail with this link. ";
SimpleMailMessage email = new SimpleMailMessage();
email.setTo(recipientAddress);
email.setSubject(subject);
email.setText(message + "\n\n" + confirmationUrl + "\n\n\nw/ AntiSocial Team");
mailSender.send(email);
}
示例4: sendPasswordResetMail
import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
/**
* パスワードリセット案内メールを送信します。
*
* @param request パスワードリセット要求
*/
@Async
void sendPasswordResetMail(PasswordResetRequest request) {
SimpleMailMessage message = new SimpleMailMessage();
message.setReplyTo(appReply);
message.setTo(request.getMembership().getEmail());
message.setSubject("【パスワードリセット】Java研修 Go研修 OB・OG会");
message.setText(request.getMembership().getName() + " さん\n\n" +
"パスワードリセットの要求を受け付けました。\n" +
"下記 URL から 24 時間以内にパスワードリセットを行ってください。\n\n" +
appUrl + "/#!" + ResetPasswordView.VIEW_NAME + "/" + request.getToken() + "\n" +
"※トップページにリダイレクトされてしまう場合は、トップページを開いた画面 (タブ) のアドレス欄に" +
"上記 URL を張り付けて移動してください。\n\n" +
"本メールに関するお問合せ先: " + appReply + "\n" +
"Java研修 Go研修 OB・OG会");
try {
mailSender.send(message);
} catch (MailException e) {
exceptionHandler.accept(e);
}
}
示例5: sendUpdateMail
import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
/**
* メンバー情報更新完了メールを送信します。
*
* @param membership メンバー情報
*/
@Async
void sendUpdateMail(Membership membership) {
SimpleMailMessage message = new SimpleMailMessage();
message.setReplyTo(appReply);
message.setBcc(appReply);
message.setTo(membership.getEmail());
message.setSubject("【会員情報編集完了】Java研修 Go研修 OB・OG会");
message.setText(membership.getName() + " さん\n\n" +
"会員情報の編集が完了しました。\n\n" +
"詳細の確認・登録内容の変更は以下 URL より行ってください。\n" +
appUrl + "\n\n" +
"本メールに関するお問合せ先: " + appReply + "\n" +
"Java研修 Go研修 OB・OG会");
try {
mailSender.send(message);
} catch (MailException e) {
exceptionHandler.accept(e);
}
}
示例6: 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);
logger.info("邮件已经发送!");
}catch (Exception e){
logger.error("发送邮件发生异常!",e);
}
}
示例7: 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);
}
}
示例8: doRegister
import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
@RequestMapping(value = "/register", method = RequestMethod.POST)
public String doRegister(@Valid @ModelAttribute UserModel newUserModel, BindingResult bindingResult, Model model) {
if (newUserModel.getPassword().length() < 14)
return "register2";
else {
// Password encryption
newUserModel.setPassword(passwordEncoder.encode(newUserModel.getPassword()));
userRepository.save(newUserModel);
// Create user-role for the user
UserRoleModel role = new UserRoleModel();
role.setRole("ROLE_USER");
role.setUser(newUserModel);
userRoleRepository.save(role);
//Send verification mail
SimpleMailMessage msg = new SimpleMailMessage(this.customMailMessage);
msg.setTo(newUserModel.getEmail_address());
msg.setText(String.format(msg.getText(), newUserModel.getUsername(), "http://localhost:8080/Towan/verification?id="+newUserModel.getUserId()));
this.mailSender.send(msg);
return "verifyInfo";
}
}
示例9: 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);
}
}
示例10: send
import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
public void send(String fromEmail, String toEmail,String subject, String text) {
LOG.info("Starting Send...");
this.templateMessage = new SimpleMailMessage();
this.templateMessage.setSubject(subject);
this.templateMessage.setFrom(fromEmail);
this.templateMessage.setTo(toEmail);
SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
msg.setText(text);
LOG.info(templateMessage.toString());
try {
this.mailSender.send(msg);
} catch (MailException ex) {
LOG.error(ex.getMessage());
}
LOG.info("Finished Send...");
}
示例11: 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);
}
示例12: 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");
}
示例13: run
import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public void run() {
Locale currentLocale = email.getLocale();
LOG.debug("Current locale: " + currentLocale);
LOG.debug("Sending mail to: " + this.email.getAddress());
ResourceBundle emailConfirmationResources = ResourceBundle
.getBundle("one-time-password", currentLocale);
SimpleMailMessage simpleMessage = new SimpleMailMessage();
simpleMessage.setTo(this.email.getAddress());
simpleMessage.setSubject(emailConfirmationResources
.getString("subject"));
String text = emailConfirmationResources.getString("text");
text = StringUtils.replace(text, "${identifier}", email.getUser()
.getIdentifier());
text = StringUtils.replace(text, "${password.plaintext}", password
.getPlaintext());
text = StringUtils.replace(text, "${serverBaseUrl}", email
.getUser().getDomain().getRuntime().getServerBaseUrl()
.toString());
simpleMessage.setText(text);
mailSender.send(simpleMessage);
}
示例14: execute
import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
@Override
public void execute(ExecutionContext executionContext) {
MailSender mailSender = executionContext.service(MailSender.class);
String confirmationCode = UUID.randomUUID().toString();
executionContext.setProperty(ForgotPasswordFlow.confirmationCode, confirmationCode);
SimpleMailMessage confirmationMail = new SimpleMailMessage();
confirmationMail.setFrom("[email protected]");
confirmationMail.setSubject("Your Password Reset Request");
confirmationMail.setTo(executionContext.property(ForgotPasswordFlow.emailAddress));
confirmationMail.setText(new MailTemplates()
.create("passwordRequest")
.replace("code", confirmationCode)
.getText()
);
mailSender.send(confirmationMail);
log.info("sent confirmation");
}
示例15: sendMessage
import org.springframework.mail.SimpleMailMessage; //导入方法依赖的package包/类
/**
* Send a simple message based on a Velocity template.
* @param msg the message to populate
* @param templateName the Velocity template to use (relative to classpath)
* @param model a map containing key/value pairs
*/
public void sendMessage(SimpleMailMessage msg, String templateName, Map model) {
String result = null;
try {
result =
VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
templateName, "UTF-8", model);
} catch (VelocityException e) {
e.printStackTrace();
log.error(e.getMessage());
}
msg.setText(result);
send(msg);
}