Есть ли способ заменить следующий код записью в файле application.properties:
Свойства props = this.mailSender.getJavaMailProperties (); props.put ("mail.smtp.starttls.enable", "true");
С Уважением




Просто поместите их в application.properties. Остальное как есть.
#SMTP configuration
spring.mail.host=smtp.gmail.com
spring.mail.port=587
[email protected]
spring.mail.password=lkkl
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.ssl.trust=smtp.gmail.com
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.writetimeout=5000
Напишите такой класс отправителя почты
@Service
public class EmailServiceImpl implements EmailService {
@Autowired
public JavaMailSender emailSender;
private final String imageLink = "images/teddy.jpeg";
private final String imageNameToSend = "teddy.jpeg";
@Override
public void sendSimpleMessage(String to, String subject, String text) throws IOException, MessagingException {
MimeMessage message = emailSender.createMimeMessage();
MimeMessageHelper helper = null;
try {
helper = new MimeMessageHelper(message, true);
helper.setTo(to);
helper.setSubject(subject);
FileSystemResource file
= new FileSystemResource(new ClassPathResource(imageLink).getFile());
helper.addAttachment(imageNameToSend, file);
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(text, "text/html");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
emailSender.send(message);
} catch (MessagingException | IOException e ) {
log.info("Exception catched {}",e);
throw e;
}
}
}
Электронная почта будет такой
public interface EmailService {
void sendSimpleMessage(
String to, String subject, String text) throws IOException, MessagingException;
}
Добавьте следующую библиотеку в файл build.gradle или, если вы используете другой инструмент сборки, добавьте эту библиотеку в соответствующий файл
compile('org.springframework.boot:spring-boot-starter-mail:1.5.9.RELEASE')
попробуйте с spring.mail.properties.mail.smtp.starttls.enable = false
проверьте мой обновленный код и следуйте ему. Вы также можете посмотреть этот проект github.com/sanjoy-sust/FreightManagement/tree/develop/src/ma в /…
не работает, я получил следующую ошибку: Сообщение об ошибке 1: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Сначала необходимо выполнить команду STARTTLS. k4sm31119026wrx.91 - gsmtp] с основной причиной org.springframework.mail.MailSendException: Неудачные сообщения: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Сначала необходимо ввести команду STARTTLS. k4sm31119026wrx.91 - gsmtp