Bootstrap

今天说说阿里云邮件推送配置

今天说说阿里云邮件推送配置

首先登陆然后进入控制台

image.png

打开左侧菜单找到邮件推送的菜单

image.png

这是邮件的主页面

image.png

  1. 新建发信域名 email.xxx.com image.png

  2. 点击配置 image.pngimage.png

  3. 配置域名

image.png

对应的填上就好了 然后到2的验证 就可以了 image.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("[email protected]");
            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();
        }
    }

原文地址 https://whatyun.cn/article/51

;