'The from address is being ignored spring mailer
I don't know why the from address is being ignored and it is set to [email protected]
@Service
public class EmailSenderService {
@Autowired
private JavaMailSender mailSender;
public void sendEmail(String fromEmail,String toEmail, String subject, String body){
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(fromEmail);
message.setTo(toEmail);
message.setText(body);
message.setSubject(subject);
mailSender.send(message);
System.out.println("Mail sent successfully...");
}
}
I send mail using SimpleMailMessage. Everything is working nicely. But I don't know why on the receiver side shows spring.mail.username's address and not the From Adress. Each mail sent to the right address but from the address mail which is created in property spring.mail.username What method will use for this?
@EventListener(ApplicationReadyEvent.class)
public void sendMail() {
senderService.sendEmail("[email protected]",
"[email protected]",
"this is the subject",
"this is the body");
}
#Spring mailer properties
spring.mail.host=smtp.gmail.com
spring.mail.port=587
[email protected]
spring.mail.password=vryzdntajjbllkdt
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
Solution 1:[1]
In application.properties file, you need to pass host, port, username and password of From mail id. There is no meaning in providing credentials of To_Address in application. Authentication is required for a sender. Hope it helped.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ankitha J |
