package dgut.ke.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
public class MailTest {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
JavaMailSender mailSender = (JavaMailSender) context.getBean("mailSender");
SimpleMailMessage mail = new SimpleMailMessage();
mail.setFrom("sskwfnihc@gmail.com");
mail.setTo("sskwfnihc@163.com");
mail.setSubject("KE给你发了一封邮件");
mail.setText("This is a mailTest example");
mailSender.send(mail);
System.out.println("成功发送文本文件!");
}
}
spring配置文件:
... ...
<!-- 发送电子邮件 -->
<bean id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="host" value="smtp.gmail.com"></property>
<property name="port" value="465"></property>
<property name="username">
<value>sskwfnihc</value>
</property>
<property name="password">
<value>write your password here</value>
</property>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
</props>
</property>
</bean>
... ...
posted on 2007-11-15 22:35
Ke 阅读(408)
评论(0) 编辑 收藏 所属分类:
spring