今天說說阿里雲郵件推送配置

首先登錄而後進入控制檯java

clipboard.png

打開左側菜單找到郵件推送的菜單maven

clipboard.png

這是郵件的主頁面spa

clipboard.png

新建發信域名 email.xxx.com code

clipboard.png

點擊配置ip

clipboard.png

配置域名get

clipboard.png

對應的填上就行了 而後到2的驗證 就能夠了域名

clipboard.png

代碼實現 -添加maven

 <!--發送郵件-->
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-dm</artifactId>
            <version>3.1.0</version>
        </dependency>
代碼實現
     /**
     * @param code
     */
    public static void sendRegisterCode(String code, String email) {

        // 若是是除杭州region外的其它region(如新加坡、澳洲Region),須要將下面的"cn-hangzhou"替換爲"ap-southeast-1"、或"ap-southeast-2"。
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "xxxx", "xxx");
        IAcsClient client = new DefaultAcsClient(profile);
        SingleSendMailRequest request = new SingleSendMailRequest();

        try {
            request.setAccountName("xxx@email.xxxx.cn");
            request.setFromAlias("xxxxx");
            request.setAddressType(1);
            request.setTagName("register");
            request.setReplyToAddress(true);
            request.setToAddress(email);
            request.setSubject("xxx 註冊帳號");
            request.setHtmlBody("您的驗證碼是:" + code);
            SingleSendMailResponse httpResponse = client.getAcsResponse(request);

            System.out.println(httpResponse);
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
相關文章
相關標籤/搜索