1.通过 xml 文件配置主要属性:
xml 文件:test.xml
view plaincopy to clipboardprint?
<bean id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.126.com" />
<property name="port" value="25" />
<property name="username" value="dxxx@126.com" />
<property name="password" value="xxxxxxx" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
</props>
</property>
</bean>
<bean id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.126.com" />
<property name="port" value="25" />
<property name="username" value="dxxx@126.com" />
<property name="password" value="xxxxxxx" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
</props>
</property>
</bean>
java 发送代码:
a.text 文字发送模式:
view plaincopy to clipboardprint?
//获得 xml 文件环境
ApplicationContext context = new
ClassPathXmlApplicationContext("test.xml");
//取得配置
JavaMailSender mailSender = (JavaMailSender)
context.getBean("mailSender");
SimpleMailMessage mail = new SimpleMailMessage();
mail.setFrom("xxxxxx@126.com");
mail.setTo("ddddd@126.com");
评论2