Announcement Announcement Module
No announcement yet.
SimpleMailMessage to and from issue Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • SimpleMailMessage to and from issue

    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("[email protected]"); still does not work. Any ideas?


    //implementation class:

    public class MailService {

    private MailSender mailSender;
    private SimpleMailMessage alertMailMessage;

    public void sendMail(String from, String to, String subject, String body) {

    SimpleMailMessage message = new SimpleMailMessage();


    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailS enderImpl">
    <property name="host" value=""/>
    <property name="port" value="25"/>
    <property name="username" value="[email protected]"/>
    <property name="password" value="xxxx"/>
    <property name="javaMailProperties">
    <!-- 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>

  • #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.


    • #3
      SimpleMailMessage to and from issue

      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?


      • #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.