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

  • 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("[email protected]"); 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="[email protected]"/>
    <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>

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

    Comment


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

      Comment


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

        Comment

        Working...
        X