java編寫郵件發送

當前使用github的一個簡單郵件發送實例:

https://github.com/biezhi/oh-my-email

 

使用配置maven:

<dependency>
            <groupId>io.github.biezhi</groupId>
            <artifactId>oh-my-email</artifactId>
            <version>0.0.4</version>
        </dependency>

配置 發送者賬戶:這裏使用QQ的發送實例,密碼使用qq授權密碼 也可以自定義配置properties

@Before
    public void before() throws GeneralSecurityException {
        // 配置,一次即可
        OhMyEmail.config(SMTP_QQ(true), "[email protected]", "xxx");
    }

調用發送郵件方法:

@Test
    public void testSendHtml() throws SendMailException {
        OhMyEmail.subject("這是一封測試HTML郵件")
                .from("[email protected]")
                .to("[email protected]").from("xx", "[email protected]")
                .html("<h1 font='red' style='color:green'>信件內容</h1>" + System.currentTimeMillis())
                .send();
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章