需要的spring的jar包有:spring.jar,mail.jar,commons-logging.jar,activation.jar
- package mail;
-
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- import org.springframework.mail.SimpleMailMessage;
- import org.springframework.mail.javamail.JavaMailSender;
-
- public class Main {
-
-
-
-
- public static void main(String[] args) {
-
- ApplicationContext context = new ClassPathXmlApplicationContext("config.xml");
- JavaMailSender mailSender= (JavaMailSender) context.getBean("mailSender");
- SimpleMailMessage mail = new SimpleMailMessage();
- mail.setFrom("abcd@163.com");
- mail.setTo("abcd@gmail.com");
- mail.setSubject(" 测试spring Mail");
- mail.setText("hello,java");
- mailSender.send(mail);
- }
-
- }
package mail;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext context = new ClassPathXmlApplicationContext("config.xml");
JavaMailSender mailSender= (JavaMailSender) context.getBean("mailSender");
SimpleMailMessage mail = new SimpleMailMessage();
mail.setFrom("abcd@163.com");
mail.setTo("abcd@gmail.com");
mail.setSubject(" 测试spring Mail");
mail.setText("hello,java");
mailSender.send(mail);
}
}
config.xml配置文件:
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd"
- >
- <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
- <property name="host" value="smtp.163.com" />
- <property name="port" value="25" />
- <property name="username" value="abcd@163.com" />
- <property name="password" value="你的密码" />
- <property name="javaMailProperties">
- <props>
- <prop key="mail.smtp.auth">true</prop>
- </props>
- </property>
- </bean>
- </beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd"
>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.163.com" />
<property name="port" value="25" />
<property name="username" value="abcd@163.com" />
<property name="password" value="你的密码" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
</props>
</property>
</bean>
</beans>
分享到:
相关推荐
Spring mail发送邮件实例 Spring mail发送邮件实例
使用Spring mail发送邮件的完整实例,包含代码与Spring mail的jar,可直接运行与使用。相关学习文档参考博客《Spring Mail邮件发送 http://blog.csdn.net/chenxiang0207/article/details/8256528》。
java 发送邮件 spring发送邮件Mail
spring发送 email 发送html格式数据,普通数据,附件,图片等邮件
spring boot发送普通文本邮件/HTML邮件/附件邮件/图片邮件完整代码.zip
NULL 博文链接:https://longjuanfeng885.iteye.com/blog/1895577
项目主要是使用 Spring Boot 发送邮件,主要的技术点有: 1、Spring Boot +mybatis的整合 2、Spring Boot项目中jsp的使用 3、Spring Boot 发送邮件(文本格式的邮件、发送HTML格式的邮件、发送带附件 的邮件、...
这个java project的源代码 博文链接:https://kukuqiu.iteye.com/blog/161771
spring + mail + 发送邮件 demo
本篇文章主要介绍了使用spring mail发送html邮件的示例代码,这里整理了详细的示例代码,具有一定的参考价值,有兴趣的可以了解一下
NULL 博文链接:https://wang3065.iteye.com/blog/1718381
Spring实现各种邮件的发送 简单配置就可发送邮件
spring mail 的发送 mail spring mail demo 示例
SpringMail.rar SpringMail发邮件
Spring邮件发送服务(java邮件发送),支持多附件、多人发送/抄送/暗送
利用spring下的一个类进行邮件发送,内附具体用法
spring+velocity发送邮件,spring+velocity发送邮件
Spring整合Quartz定时发送邮件