当前位置: 首页 > news >正文

react native android设置邮箱,进行邮件发送

react native android设置邮箱,进行邮件发送

  1. 引入发送邮件的架包。
    在build.gradle 的dependencies 下引入:

     //发送邮件的依赖implementation 'com.sun.mail:android-mail:1.6.7'implementation 'com.sun.mail:android-activation:1.6.7'
    
  2. 导入EmailSender类

     import android.widget.Toast;import java.util.Properties;import javax.mail.Authenticator;import javax.mail.Message;import javax.mail.MessageRemovedException;import javax.mail.MessagingException;import javax.mail.PasswordAuthentication;import javax.mail.Session;import javax.mail.Transport;import javax.mail.internet.InternetAddress;import javax.mail.internet.MimeMessage;public class EmailSender {private String username;private String password;private String host;private String port;public EmailSender(String username,String password,String host,String port){this.username = username;this.password = password;this.host = host;this.port = port;}public void sendEmail(String to, String subject , String text){Properties properties = new Properties();properties.put("mail.smtp.auth",true);properties.put("mail.smtp.starttls.enable",true);properties.put("mail.smtp.host",host);properties.put("mail.smtp.port",port);Session session = Session.getInstance(properties, new Authenticator() {@Overrideprotected PasswordAuthentication getPasswordAuthentication() {return new PasswordAuthentication(username,password);}});try {Message message = new MimeMessage(session);message.setFrom(new InternetAddress(username));message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to));message.setSubject(subject);message.setText(text);Transport.send(message);} catch (MessagingException e){e.printStackTrace();}}}
    
  3. 在NativeModule 中调用。

username:账户名、邮箱
password:密码
host:主机
port:端口
to:发送的邮箱
subject:主题
text:内容

	@ReactMethodpublic void sendEmail(String username,String password,String host,String port,String to,String subject,String text) {new Thread(new Runnable() {@Overridepublic void run() {EmailSender emailSender = new EmailSender(username,password,host,port);emailSender.sendEmail(to,subject,text);}}).start();}
http://www.dtcms.com/a/461491.html

相关文章:

  • Java面试场景:从Spring Boot到Kubernetes的技术问答
  • 从潜在空间到实际应用:Embedding模型架构与训练范式的综合解析
  • Vue3 provide/inject 详细组件关系说明
  • php的网站架构建设框架嘉兴网站设计
  • Redis(四)——Redis主从同步与对象模型
  • 2016年网站建设总结培训学校
  • 网站最下端怎么做动画设计培训机构
  • 用python制作相册浏览小工具
  • 字节跳动ByteDance前端考前总结
  • codex使用chrome-devtools-mcp最佳实践
  • 【Linux命令从入门到精通系列指南】export 命令详解:环境变量管理的核心利器
  • python 自动化采集 ChromeDriver 安装
  • 苏州招聘网站建设推广费
  • java8提取list中对象有相同属性值的对象或属性值
  • cuda编程笔记(26)-- 核函数使用任务队列
  • 存储芯片核心产业链研发实力:兆易创新、北京君正、澜起科技、江波龙、长电科技、佰维存储,6家龙头公司研发实力深度数据
  • 《Seq2Time: Sequential Knowledge Transfer for Video LLMTemporal Grounding》
  • 山东省建设部网站官网网站备案审核通过后
  • 浏览器兼容性问题处理
  • Day 09(下) B2a实例解说----exampleB2a.cc+ActionInitialization+PrimaryGeneratorAction
  • 分布式锁:Redisson的可重入锁
  • 计算机硬件相关(AI回答)
  • 网站设计中的用户体验大型网站需要什么样的团队
  • 淘宝网站开发方式网站托管 济南
  • 重庆网站seo案例网站推广用什么方法最好
  • sql报错:java.sql.SQLSyntaxErrorException: Unknown column ‘as0‘ in ‘where clause‘
  • 做网站是什么公司做陶瓷公司网站
  • CentOS 7上安装SonarQube8.9
  • 遗留系统微服务改造(二):数据迁移实战攻略与一致性保证
  • IO操作(Num22)