您好我是初学者,试图在我的Tomcat服务器上运行邮件通知服务.当我在本地运行此代码时,它可以正常工作,但是当我在远程服务器上部署它时.我得到"javax.mail.MessagingException:无法确定本地电子邮件地址".我的服务器上有SSL证书,这可能是原因造成的吗?
请你好,如果你认为我忘记了什么,写下来,我会更新帖子.谢谢,这是我的代码.
applicationContext.xml中
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.gmail.com" />
<property name="port" value="25" />
<property name="username" value="mymail@gmail.com" />
<property name="password" value="mypassword" />
<property name="javaMailProperties">
<props>
<prop key="mail.transport.protocol">smtp</prop>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.debug">true</prop>
</props>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
MailService.java
@Autowired
private MailSender mailSender;
public void sendEventMailToUser(Event event) {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(event.getUser().getEmail().trim());
message.setSubject("appName");
message.setText("Mymessage");
mailSender.send(message);
}
Run Code Online (Sandbox Code Playgroud)
从我的邮件调试
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 25, isSSL …Run Code Online (Sandbox Code Playgroud)