阿里云收发邮件的服务器(配置阿里云邮件推送及代码实现邮件发送)
首先登陆然后进入控制台
打开左侧菜单找到邮件推送的菜单
这是邮件的主页面
新建发信域名 email.xxx.com
点击配置
配置域名
对应的填上就好了 然后到2的验证 就可以了
代码实现 -
添加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(); } }
文章是本人在工作中学习终结得到,如果有不对的地方,请小伙伴们私聊或者评论一起探讨。
,免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com