05月12, 2017

java发送邮件示例

maven依赖

<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.6.0-rc1</version>
</dependency>

<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.0-rc1</version>
</dependency>

spring SendMail

<bean id="mailSSLSocketFactory" class="com.sun.mail.util.MailSSLSocketFactory">
        <property name="trustAllHosts" value="true"></property>
    </bean>

    <bean id="javaMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="javaMailProperties">
            <map>
            <entry key="mail.smtp.auth" value="true"></entry>
            <entry key="mail.smtp.timeout" value="25000"></entry>
            <entry key="mail.debug" value="false"></entry>
            <entry key="mail.smtp.ssl.enable" value="true"></entry>
            <entry key="mail.smtp.port" value="465"></entry>
            <entry key="mail.smtp.ssl.socketFactory" value-ref="mailSSLSocketFactory" ></entry>
            </map>
        </property>
        <property name="host" value="smtp.qq.com" />
        <property name="username" value="service@qq.com" />
        <property name="password" value="psw" />
    </bean>

本文链接:https://blog.jnliok.com/post/tools-java-sendmail.html

-- EOF --

Comments