首先登陆然后进入控制台

clipboard.png

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

clipboard.png

这是邮件的主页面

clipboard.png

新建发信域名 email.xxx.com

clipboard.png

点击配置

clipboard.png

clipboard.png

配置域名

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();
    }
}

ByteBlogs
6 声望1 粉丝