乐趣区

阿里云邮件推送配置

首先登陆然后进入控制台

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

这是邮件的主页面

新建发信域名 email.xxx.com

点击配置

配置域名

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("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();
    }
}
退出移动版