美文网首页
IredMail邮箱服务java代码测试

IredMail邮箱服务java代码测试

作者: loveFXX | 来源:发表于2019-10-18 11:42 被阅读0次

首先添加maven依赖

<dependency>

         <groupId>org.springframework.boot</groupId>

           <artifactId>spring-boot-starter-mail</artifactId>

</dependency>

测试代码

import org.springframework.mail.SimpleMailMessage;

import org.springframework.mail.javamail.JavaMailSender;

import org.springframework.mail.javamail.JavaMailSenderImpl;

public class test {

    public static void main(String[] args) {

        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();

        //iredMail 服务域名

        mailSender.setHost( "mail.xxxxxx.com" );

        mailSender.setPort( 25 );

        mailSender.setProtocol( "smtp" );

        //iredMail 首个邮箱用户名

        mailSender.setUsername( "postmaster@xxxxxx.com" );

        //iredMail 首个邮箱密码

        mailSender.setPassword( "xxxxxxxxxxxxxxxxxx" );

        mailSender.setDefaultEncoding( "UTF-8" );

        SimpleMailMessage message = new SimpleMailMessage();

        message.setFrom("postmaster@xxxxxx.com");

        //发给谁

        message.setTo("xxxxx@qq.com");

        message.setSubject( "Verification Code");

        message.setText("hello");

        mailSender.send(message);

        System.out.println("success");

    }

}

相关文章

网友评论

      本文标题:IredMail邮箱服务java代码测试

      本文链接:https://www.haomeiwen.com/subject/tcdimctx.html