我正在使用谷歌的电子邮件服务(使用我的自定义域名)。我想使用动态发件人电子邮件地址,即当用户注册时,他应该从register@example.com接收电子邮件,当他下订单时,应该收到来自orders@example.com的电子邮件
我使用java邮件发送电子邮件,应用程序是使用spring框架开发的。发送电子邮件,只发出它们始终从spring配置xml中指定的用户名接收。
Spring配置:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.gmail.com" />
<property name="port" value="587" />
<property name="username" value="username" />
<property name="password" value="password" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
</props>
</property>
</bean>
MimeMessagePreparator preparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
mimeMessage.setRecipient(Message.RecipientType.TO,
new InternetAddress(order.getCustomer().getEmailAddress()));
mimeMessage.setFrom(new InternetAddress("mail@mycompany.com"));
mimeMessage.setText(
"Dear " + order.getCustomer().getFirstName() + " "
+ order.getCustomer().getLastName()
+ ", thank you for placing order. Your order number is "
+ order.getOrderNumber());
}
};
任何想法,我哪里出错了?