Tag: Spring Send mail Spring Mail
Based on spring framework
Three simple steps:
Guide Package
Configuration XML
Interface calls
XML configuration:
<?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-2.5.xsd ">
<bean class= "Org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
<bean id= "Simpmail" class= "Org.springframework.mail.SimpleMailMessage" >
<property name= "from" value= "[email protected]"/>
</bean>
<bean id= "MailSender" class= "Org.springframework.mail.javamail.JavaMailSenderImpl" > <!--host, username, password, etc. Configuration-
<property name= "Host" ><value>smtp.163.com</value></property>
<property name= "username" ><value>[email protected]</value></property>
<property name= "Password" ><value>8888</value></property>
<property name= "Port" ><value>25</value></property>
<property name= "Javamailproperties" >
<props>
<prop key= "Mail.smtp.auth" >true</prop>
<prop key= "Mail.smtp.timeout" >25000</prop>
</props>
</property>
</bean>
</beans>
Main test method:
Package mytools.framework.jmail;
Import Org.springframework.context.ApplicationContext;
Import Org.springframework.context.support.ClassPathXmlApplicationContext;
Import Org.springframework.mail.SimpleMailMessage;
Import Org.springframework.mail.javamail.JavaMailSender;
public class Jmailmain
{
public static void Main (string[] args)
{
String[] locatoins={"Applicationcontext.xml"};
ApplicationContext context=new Classpathxmlapplicationcontext (locatoins);
Javamailsender sender= (Javamailsender) Context.getbean ("MailSender");
Simplemailmessage simpmail= (simplemailmessage) Context.getbean ("Simpmail");
Simpmail.setto ("[email protected]"); Destination Mailbox
Simpmail.setsubject ("subject"); Theme
Simpmail.settext ("content"); Content
Sender.send (Simpmail);
}
}
Send Java applets from spring-based mail