Skip to content

👷 一A simple and easy-to-use minimal mail sending library, supporting annotations.

License

Notifications You must be signed in to change notification settings

jatin7/NiceEmail

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NiceEmail - 3.0.0

Mail sending library supporting various functions

characteristic

  • Simple email sending API
  • Support custom sender nickname
  • Support email to send verification code
  • Support sending HTML / attachments
  • Support asynchronous sending
  • Custom annotations, more simple and convenient

how to use

maven coordinates

<dependency>
    <groupId>io.github.isliqian</groupId>
    <artifactId>NiceEmail</artifactId>
    <version>3.0.0</version>
</dependency>

Sample

           @Before
           public void before(){
               // 配置,一次即可:邮箱与密码
               NiceEmail.config(NiceEmail.SMTP_QQ(), "51103942@qq.com", "jtmoybnwknrnbjha");
           }
       
           /**
            * 测试发送文字
            * @throws MessagingException
            */
           @Test
           public void testSendText() throws MessagingException {
               NiceEmail.subject("这是一封测试TEXT邮件")//主题
                       .from("LqNice")//发件人昵称
                       .to("???@qq.com")//收件人
                       .text("信件内容")//内容
                       .send();//发送
           }
       
           /**
            * 测试发送Html
            * @throws MessagingException
            */
           @Test
           public void testSendHtml() throws MessagingException {
               NiceEmail.subject("这是一封测试HTML邮件")
                       .from("LqNice")
                       .to("51103942@qq.com")
                       //html内容即可
                       .html("<h1>信件内容</h1>")
                       .send();
           }
       
           /**
            * 测试附件邮件
            * @throws MessagingException
            */
           @Test
           public void testSendAttach() throws MessagingException {
               NiceEmail.subject("这是一封测试附件邮件")
                       .from("LqNice")
                       .to("51103942@qq.com")
                       .html("<h1 font=red>信件内容</h1>")
                       //附近的路径,以及名称
                       .attach(new File("/Users/DELL/Pictures/Saved Pictures/000028.jpg"), "测试图片.jpeg")
                       //名称可以不设置
                       //.attach(new File("/Users/DELL/Pictures/Saved Pictures/000028.jpg"))
                       .send();
           }
           /**
            * 测试发送验证码
            * @throws MessagingException
            */
           @Test
           public void testSendVerifcationCode() throws MessagingException{
               NiceEmail.subject("来自远方的验证码")
                         .from("LqNice")
                         .to("51103942@qq.com")
                          //验证码长度为6,如果类型为null,验证码类型为数字英文混合验证码
                         .verificationCode(6,null)
                         //支持纯英文验证码
                         //.verificationCode(4,verificationEnglishArrary)
                         //如果验证码位数不配置,则按照6位验证码发送
                         //.verificationCode(0,verificationNumberArrary)
                         .send();
       
           }

New features

How to use @AnnNiceConfig + @AnnNiceEmail

@AnnNiceConfig(type = "SMTP_QQ",
     username = "jatin777@qq.com",
     password = "jtmoybnwknrnbjha")
public class TestAnnEmail {

 @Test
 @AnnNiceEmail(subject = "测试注解发送文本邮件",
         from = "LqNice",
         to="51103942@qq.com",
         text = "text Ann text")
 public void sendTextEmail() throws InvocationTargetException, IllegalAccessException, MessagingException {
     send(TestAnnEmail.class);
 }



 @Test
 @AnnNiceEmail(subject = "测试注解发送Html邮件",
         from = "LqNice",
         to="51103942@qq.com",
         html = "<h1>test Ann Html</h1>")
 public void sendHtmlEmail() throws IllegalAccessException, MessagingException, InvocationTargetException {
    send(TestAnnEmail.class);

 }
}

Note that when using the verification code,

if the first input is incorrect, the next transmission will double the number of digits. . . .

personal blog author 51103942@qq.com

About

👷 一A simple and easy-to-use minimal mail sending library, supporting annotations.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%