Send Java applets from spring-based mail

Source: Internet
Author: User

Tag: Spring Send mail Spring Mail

Based on spring framework

Three simple steps:

    1. Guide Package

    2. Configuration XML

    3. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.