【发布时间】:2019-01-22 15:35:49
【问题描述】:
我使用 Gmail Server 实现了 Java Mail 服务。它工作正常。但我想用 no-rely@domain.com 发送电子邮件
我使用 Spring-Boot starter mail 实现了 Java 邮件服务。在应用程序属性中,我设置了身份验证和服务器端口。之后,我实现了Email服务并发送使用的JavaMailSender。
Application.yml
mail:
host: smtp.gmail.com
port: 587
username:
password:
properties:
mail:
smtp:
auth: true
starttls:
enable: true
MailService:
public class EmailServiceImpl implements EmailService {
@Autowired
private JavaMailSender mailSender;
/**
* Send email.
*
* @param to the to
* @param subject the subject
* @param text the text
*/
@Override
public void sendEmail(String to, String subject, String text) {
try {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(to);
message.setSubject(subject);
message.setText(text);
mailSender.send(message);
} catch (MailException e) {
log.info("Mail Exception {}", e);
}
}
我有 2 个问题。
第一季度。没有授权如何实施?我只想向用户发送一封电子邮件,以便他了解状态。
第二季度。我想从“no-reply@domain.com”发送一封电子邮件。所以没有人回复这封邮件。
【问题讨论】:
标签: java spring-boot jakarta-mail