-
Dec 8th, 2011, 05:24 AM
#1
SimpleMailMessage to and from issue
Hi,
Iīve got the following code up and running, see below:
My question is, I am receiving emails on my gmail account but the from is always myself and not the personīs email address, even if I hardcode it in the implementation class as message.setFrom("somebody@hotmail.com"); still does not work. Any ideas?
...
//implementation class:
@Service("mailService")
public class MailService {
@Autowired
private MailSender mailSender;
@Autowired
private SimpleMailMessage alertMailMessage;
public void sendMail(String from, String to, String subject, String body) {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(from);
message.setTo(to);
message.setSubject(subject);
message.setText(body);
mailSender.send(message);
}
....
//servlet-...xml
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailS enderImpl">
<property name="host" value="smtp.gmail.com"/>
<property name="port" value="25"/>
<property name="username" value="xxx@gmail.com"/>
<property name="password" value="xxxx"/>
<property name="javaMailProperties">
<props>
<!-- Use SMTP transport protocol -->
<prop key="mail.transport.protocol">smtp</prop>
<!-- Use SMTP-AUTH to authenticate to SMTP server -->
<prop key="mail.smtp.auth">true</prop>
<!-- Use TLS to encrypt communication with SMTP server -->
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.debug">true</prop>
</props>
</property>
</bean>
-
Dec 8th, 2011, 07:13 AM
#2
Please use [ code][/code ] tags when posting code that way it remains readable
...
With gmail you can only send emails out of your own name, regardless of what you put in the from field.
-
Dec 8th, 2011, 09:15 AM
#3
SimpleMailMessage to and from issue
Hi,
Sorry about the code tags. Iīll put the next time.
So, If someone logs into my web application and sends me an email, there is no way of getting the from set to this personīs email address....this with GMAIL, but what about using yahoo, hotmail or even my with GoDaddy .
Is this the way SimpleMailMessage works?
-
Dec 8th, 2011, 12:21 PM
#4
This has nothing to do with the mail message or spring it has to do with your mail provider. In general when sending mail through smtp the only from address accepted is your own (the user you login with) this is to prevent spam and to prevent anyone sending mail through your server.
How the other smtp servers operate I have no clue but google simply replaces the from with your gmail account if you use it to send mail.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules