密码验证的电子邮件在春天发送

时间:2014-07-17 09:27:28

标签: java email spring-mvc spring-security

如何验证电子邮件ID的密码。目前它是在没有身份验证的情况下发送邮件,因此如何验证property文件中给出的mail.username的密码。     在spring-servlet中下面的代码:

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${mail.host}" />
<property name="port" value="${mail.port}" />
<property name="username" value="${mail.username}" />
<property name="password" value="${mail.password}" />
<property name="javaMailProperties">
<props>
<prop key="mail.transport.protocol">smtp</prop>
<prop key="mail.smtps.auth">true</prop>
<prop key="mail.smtp.starttls.enable">false</prop>
<!-- <prop key="mail.smtp.debug">true</prop>  -->
</props>
</property>
  </bean>

**Mail Sending Part :**
SimpleMailMessage email = new SimpleMailMessage();
if(UserEmailId != null){
email.setFrom(userFrom);
email.setTo(UserEmailId);
email.setSubject(subject);
email.setText(MessageBody);
mailSender1.send(email);    
}

**mail property file :**
#Email address/account for sending emails from system.
mail.username=<from email id>

#Password for accessing email account
mail.password=<password>

#Mail server hostname or IP
mail.host=<host>

#Mail server port
mail.port=25

#Mail transport protocol
mail.transport.protocol=smtp

#Mail authentication enabled true/false
mail.smtp.auth=true

#smtp TLS enable true/false
mail.smtp.starttls.enable=false

1 个答案:

答案 0 :(得分:0)

设置以下为true,然后重试

<prop key="mail.smtp.starttls.enable">true</prop>

希望有所帮助