Merged
fix: fix missing callback, URI concatenation, and naming issues. update version:6.3.1-beta.2 #22
liangtaoAdd on Sep 29
fix: fix missing callback, URI concatenation, and naming issues. update version:6.3.1-beta.2 #22
Merged
Total: 12 files changed+826-24
| @@ -1,7 +1,55 @@ | |||
| 1 | -# v6.3.1-beta.1 | 1 | +# Changelog |
| 2 | -* feat: support autolink | ||
| 3 | 2 | ||
| 4 | -# v6.1.2-rc.1 | 3 | +## [鸿蒙化log] |
| 5 | -## 更新内容 | 4 | + |
| 6 | -* 修改组织名为@react-native-ohos | 5 | +## [6.3.1-beta.2] - 2026-09-29 |
| 7 | -* 内置Codegen生成代码 | 6 | + |
| 7 | +### Fixed | ||
| 8 | + | ||
| 9 | +- Call `callback(null, 'sent')` after `startAbility` succeeds, so the JS side can detect whether the mail app was launched successfully. ([#22](https://gitcode.com/CPF-RN/rntpc_react-native-mail/pull/22)) | ||
| 10 | +- No longer append empty `?cc=&bcc=` parameters when `ccRecipients` / `bccRecipients` are empty arrays. ([#22](https://gitcode.com/CPF-RN/rntpc_react-native-mail/pull/22)) | ||
| 11 | +- Renamed `RNMailPackge` to `RNMailPackage` (via `git mv` to preserve history), updating the `index.ets` and `ts.ets` import paths. ([#22](https://gitcode.com/CPF-RN/rntpc_react-native-mail/pull/22)) | ||
| 12 | +- Changed the Logger default log prefix from `MyApp` to `RNMail`. ([#22](https://gitcode.com/CPF-RN/rntpc_react-native-mail/pull/22)) | ||
| 13 | + | ||
| 14 | +### Changed | ||
| 15 | + | ||
| 16 | +- Migrated the repository from GitHub (br_rnoh0.82) to GitCode (master branch). ([#19](https://gitcode.com/CPF-RN/rntpc_react-native-mail/pull/19)) | ||
| 17 | +- Published the `6.3.1-beta.2` pre-release. ([#22](https://gitcode.com/CPF-RN/rntpc_react-native-mail/pull/22)) | ||
| 18 | + | ||
| 19 | +## [6.3.1-beta.1] - 2026-06-11 | ||
| 20 | + | ||
| 21 | +### Added | ||
| 22 | + | ||
| 23 | +- Added autolink support. ([#19](https://gitcode.com/CPF-RN/rntpc_react-native-mail/pull/19)) | ||
| 24 | + | ||
| 25 | +### Changed | ||
| 26 | + | ||
| 27 | +- Released `@react-native-ohos/react-native-mail@6.3.1-beta.1`, updating the har package and the package version. ([#19](https://gitcode.com/CPF-RN/rntpc_react-native-mail/pull/19)) | ||
| 28 | + | ||
| 29 | +## [6.3.0] - 2026-06-11 | ||
| 30 | + | ||
| 31 | +First stable release targeting React Native 0.82 (RNOH 0.82). | ||
| 32 | + | ||
| 33 | +### Added | ||
| 34 | + | ||
| 35 | +- react-native-mail 0.82 HarmonyOS adaptation: migrated `RNMailPackge.ts` back to `.ets` (RNOHPackage registration style), added the `index.ets` entry, and aligned the RN 0.82 dependencies. ([#19](https://gitcode.com/CPF-RN/rntpc_react-native-mail/pull/19)) | ||
| 36 | + | ||
| 37 | +### Changed | ||
| 38 | + | ||
| 39 | +- Released `@react-native-ohos/react-native-mail@6.3.0`, updating the har package and the package version. ([#19](https://gitcode.com/CPF-RN/rntpc_react-native-mail/pull/19)) | ||
| 40 | + | ||
| 41 | +## [6.2.0] - 2026-03-24 | ||
| 42 | + | ||
| 43 | +(Inherited from the br_rnoh0.77 branch's 0.77 adaptation: native modules migrated to `.ts`, Codegen C++ glue code updates, and the new CHANGELOG.md; see that branch for details.) | ||
| 44 | + | ||
| 45 | +## [6.1.2-rc.3] - 2026-01-19 | ||
| 46 | + | ||
| 47 | +(Shared base version from the br_rnoh0.72 branch: organization renamed to `@react-native-ohos`; see that branch's CHANGELOG for details.) | ||
| 48 | + | ||
| 49 | +## [6.1.2-rc.2] - 2025-12-11 | ||
| 50 | + | ||
| 51 | +(Shared base version from the br_rnoh0.72 branch: HarmonyOS Next adaptation and RNCLI/autolinking support; see that branch's CHANGELOG for details.) | ||
| 52 | + | ||
| 53 | +## [6.1.1] - 2021-08-16 | ||
| 54 | + | ||
| 55 | +Upstream [react-native-mail](https://github.com/chirag04/react-native-mail) v6.1.1, the baseline version before the HarmonyOS adaptation. See the upstream repository for earlier version history. | ||
| @@ -1,14 +1,379 @@ | |||
| 1 | -# @react-native-ohos/react-native-mail | 1 | +> 文档模板:v0.4.2 |
| 2 | 2 | ||
| 3 | -This project is based on [react-native-mail](https://github.com/chirag04/react-native-mail) | 3 | +<p align="center"> |
| 4 | + <h1 align="center"> <code>react-native-mail</code> </h1> | ||
| 5 | +</p> | ||
| 4 | 6 | ||
| 5 | -## Documentation | 7 | +本项目基于 [react-native-mail](https://github.com/chirag04/react-native-mail) 开发。 |
| 6 | 8 | ||
| 7 | -- [中文](https://gitcode.com/OpenHarmony-RN/usage-docs/blob/master/zh-cn/react-native-mail.md) | 9 | +该第三方库的仓库已迁移至 GitCode,且支持直接从 npm 下载,新的包名为:`@react-native-ohos/react-native-mail`,版本所属关系如下: |
| 8 | 10 | ||
| 9 | -- [English](https://gitcode.com/OpenHarmony-RN/usage-docs/blob/master/en/react-native-mail.md) | 11 | +| 三方库名称 | 三方库版本(npm地址) | 发布信息 | 支持RN版本 | Autolink | 编译API版本 | 社区基线版本 | 源码地址 | |
| 12 | +| --- |---------------------------------------------------------------------------------------------------| --- |--------|----------| --- | -- |------------------------------------------------------------------------------------| | ||
| 13 | +| @react-native-ohos/react-native-mail | [~6.3.0 (开发中)](https://www.npmjs.com/package/@react-native-ohos/react-native-mail) | [GitCode Releases](https://gitcode.com/CPF-RN/rntpc_react-native-mail/releases) | 0.82.* | 是 | API12+ | 6.1.1 | [master](https://gitcode.com/CPF-RN/rntpc_react-native-mail/tree/master) | | ||
| 14 | +| @react-native-ohos/react-native-mail | [~6.2.0 ](https://www.npmjs.com/package/@react-native-ohos/react-native-mail) | [GitCode Releases](https://gitcode.com/CPF-RN/rntpc_react-native-mail/releases) | 0.77.* | 否 | API12+ | 6.1.1 | [br_rnoh0.77](https://gitcode.com/CPF-RN/rntpc_react-native-mail/tree/br_rnoh0.77) | | ||
| 15 | +| @react-native-ohos/react-native-mail | [~6.1.2](https://www.npmjs.com/package/@react-native-ohos/react-native-mail) | [GitCode Releases](https://gitcode.com/CPF-RN/rntpc_react-native-mail/releases) | 0.72.* | 是 | API12+ | 6.1.1 | [br_rnoh0.72](https://gitcode.com/CPF-RN/rntpc_react-native-mail/tree/br_rnoh0.72) | | ||
| 16 | +| @react-native-oh-tpl/react-native-mail | [<= 6.1.1-0.0.1@deprecated](https://www.npmjs.com/package/@react-native-oh-tpl/react-native-mail) | [GitHub Releases(deprecated)](https://github.com/react-native-oh-library/react-native-mail/releases) | 0.72.* | 否 | API12+ | 6.1.1 | [sig](https://github.com/react-native-oh-library/react-native-mail/tree/sig) | | ||
| 10 | 17 | ||
| 11 | -## License | 18 | +## 简介 |
| 12 | 19 | ||
| 13 | -This library is licensed under [The MIT License (MIT)](https://github.com/chirag04/react-native-mail/blob/master/LICENSE) | 20 | +react-native-mail 是一个用于跳转电子邮件并新建邮件的工具库。<br/> |
| 14 | 21 | ||
| 22 | +## 下载安装 | ||
| 23 | + | ||
| 24 | +进入到工程目录并输入以下命令: | ||
| 25 | + | ||
| 26 | +**npm** | ||
| 27 | + | ||
| 28 | +```bash | ||
| 29 | +npm install @react-native-ohos/react-native-mail | ||
| 30 | +``` | ||
| 31 | + | ||
| 32 | +**yarn** | ||
| 33 | + | ||
| 34 | +```bash | ||
| 35 | +yarn add @react-native-ohos/react-native-mail | ||
| 36 | +``` | ||
| 37 | + | ||
| 38 | +## Link | ||
| 39 | + | ||
| 40 | +| 版本 | 是否支持autolink | RN框架版本 | | ||
| 41 | +|--------------------------| -------- | ------ | | ||
| 42 | +| ~ 6.3.0 | Yes | 0.82 | | ||
| 43 | + | ||
| 44 | +使用AutoLink的工程需要根据该文档配置,Autolink框架指导文档:https://gitcode.com/CPF-RN/ohos_react_native/blob/main/docs/zh-cn/02-开发/02-开发指南/Autolinking.md | ||
| 45 | + | ||
| 46 | +如您使用的版本支持 Autolink,并且工程已接入 Autolink,可跳过ManualLink配置。 | ||
| 47 | +<details> | ||
| 48 | + <summary>ManualLink: 此步骤为手动配置原生依赖项的指导</summary> | ||
| 49 | + | ||
| 50 | +首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony`。 | ||
| 51 | + | ||
| 52 | +### 1. Overrides RN SDK | ||
| 53 | + | ||
| 54 | +为了让工程依赖同一个版本的 RN SDK,需要在工程根目录的 `oh-package.json5` 添加 overrides 字段,指向工程需要使用的 RN SDK 版本。替换的版本既可以是一个具体的版本号,也可以是一个模糊版本,还可以是本地存在的 HAR 包或源码目录。 | ||
| 55 | + | ||
| 56 | +关于该字段的作用请阅读[官方说明](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-oh-package-json5-V5#zh-cn_topic_0000001792256137_overrides) | ||
| 57 | + | ||
| 58 | +```json | ||
| 59 | +{ | ||
| 60 | + "overrides": { | ||
| 61 | + "@rnoh/react-native-openharmony": "~0.82.1" // ohpm 在线版本 | ||
| 62 | + // "@rnoh/react-native-openharmony" : "./react_native_openharmony.har" // 指向本地 har 包的路径 | ||
| 63 | + // "@rnoh/react-native-openharmony" : "./react_native_openharmony" // 指向源码路径 | ||
| 64 | + } | ||
| 65 | +} | ||
| 66 | +``` | ||
| 67 | + | ||
| 68 | +### 2. 引入原生端代码 | ||
| 69 | + | ||
| 70 | +目前有两种方法: | ||
| 71 | + | ||
| 72 | +- 通过 har 包引入; | ||
| 73 | +- 直接链接源码。 | ||
| 74 | + | ||
| 75 | +方法一:通过 har 包引入(推荐) | ||
| 76 | + | ||
| 77 | +> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。 | ||
| 78 | + | ||
| 79 | +打开 `entry/oh-package.json5`,添加以下依赖 | ||
| 80 | + | ||
| 81 | +```json | ||
| 82 | +"dependencies": { | ||
| 83 | + "@react-native-ohos/react-native-mail": "file:../../node_modules/@react-native-ohos/react-native-mail/harmony/mail.har" | ||
| 84 | + } | ||
| 85 | +``` | ||
| 86 | + | ||
| 87 | +点击右上角的 `sync` 按钮 | ||
| 88 | + | ||
| 89 | +或者在命令行终端执行: | ||
| 90 | + | ||
| 91 | +```bash | ||
| 92 | +cd entry | ||
| 93 | +ohpm install | ||
| 94 | +``` | ||
| 95 | + | ||
| 96 | +方法二:直接链接源码 | ||
| 97 | + | ||
| 98 | +> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](https://gitcode.com/CPF-RN/usage-docs/blob/master/zh-cn/link-source-code.md) | ||
| 99 | + | ||
| 100 | +### 3. 配置 CMakeLists 和引入 RNMailPackage | ||
| 101 | + | ||
| 102 | +打开 `entry/src/main/cpp/CMakeLists.txt`,添加: | ||
| 103 | + | ||
| 104 | +```diff | ||
| 105 | +project(rnapp) | ||
| 106 | +cmake_minimum_required(VERSION 3.4.1) | ||
| 107 | +set(CMAKE_SKIP_BUILD_RPATH TRUE) | ||
| 108 | +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") | ||
| 109 | +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") | ||
| 110 | ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") | ||
| 111 | +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp") | ||
| 112 | +set(LOG_VERBOSITY_LEVEL 1) | ||
| 113 | +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments") | ||
| 114 | +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie") | ||
| 115 | +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use | ||
| 116 | +add_compile_definitions(WITH_HITRACE_SYSTRACE) | ||
| 117 | + | ||
| 118 | +add_subdirectory("${RNOH_CPP_DIR}" ./rn) | ||
| 119 | + | ||
| 120 | +# RNOH_BEGIN: manual_package_linking_1 | ||
| 121 | +add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package) | ||
| 122 | ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-mail/src/main/cpp" ./mail) | ||
| 123 | +# RNOH_END: manual_package_linking_1 | ||
| 124 | + | ||
| 125 | +file(GLOB GENERATED_CPP_FILES "./generated/*.cpp") | ||
| 126 | + | ||
| 127 | +add_library(rnoh_app SHARED | ||
| 128 | + ${GENERATED_CPP_FILES} | ||
| 129 | + "./PackageProvider.cpp" | ||
| 130 | + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" | ||
| 131 | +) | ||
| 132 | +target_link_libraries(rnoh_app PUBLIC rnoh) | ||
| 133 | + | ||
| 134 | +# RNOH_BEGIN: manual_package_linking_2 | ||
| 135 | +target_link_libraries(rnoh_app PUBLIC rnoh_sample_package) | ||
| 136 | ++ target_link_libraries(rnoh_app PUBLIC rnoh_mail) | ||
| 137 | +# RNOH_END: manual_package_linking_2 | ||
| 138 | +``` | ||
| 139 | + | ||
| 140 | +打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: | ||
| 141 | + | ||
| 142 | +```diff | ||
| 143 | +#include "RNOH/PackageProvider.h" | ||
| 144 | +#include "SamplePackage.h" | ||
| 145 | ++ #include "MailPackage.h" | ||
| 146 | + | ||
| 147 | +using namespace rnoh; | ||
| 148 | + | ||
| 149 | +std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) { | ||
| 150 | + return { | ||
| 151 | + std::make_shared<SamplePackage>(ctx), | ||
| 152 | ++ std::make_shared<MailPackage>(ctx) | ||
| 153 | + }; | ||
| 154 | +} | ||
| 155 | +``` | ||
| 156 | + | ||
| 157 | +### 4. 在 ArkTs 侧引入 RNMailPackage | ||
| 158 | + | ||
| 159 | +打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加: | ||
| 160 | + | ||
| 161 | +```diff | ||
| 162 | + ... | ||
| 163 | ++ import {RNMailPackage} from '@react-native-ohos/react-native-mail/ts'; | ||
| 164 | + | ||
| 165 | +export function createRNPackages(ctx: RNPackageContext): RNPackage[] { | ||
| 166 | + return [ | ||
| 167 | ++ new RNMailPackage(ctx) | ||
| 168 | + ]; | ||
| 169 | +} | ||
| 170 | +``` | ||
| 171 | + | ||
| 172 | +</details> | ||
| 173 | + | ||
| 174 | +### 运行 | ||
| 175 | + | ||
| 176 | +点击右上角的 `sync` 按钮 | ||
| 177 | + | ||
| 178 | +或者在命令行终端执行: | ||
| 179 | + | ||
| 180 | +```bash | ||
| 181 | +cd entry | ||
| 182 | +ohpm install | ||
| 183 | +``` | ||
| 184 | + | ||
| 185 | +然后编译、运行即可。 | ||
| 186 | + | ||
| 187 | +## 约束与限制 | ||
| 188 | + | ||
| 189 | +### 兼容性 | ||
| 190 | + | ||
| 191 | +本文档内容基于以下版本验证通过: | ||
| 192 | + | ||
| 193 | +1. RNOH: 0.82.7; SDK: HarmonyOS 6.0.1 Release SDK; IDE: DevEco Studio 6.0.1.260; ROM: 6.0.0.130 SP15; | ||
| 194 | + | ||
| 195 | +## 使用示例 | ||
| 196 | + | ||
| 197 | +下面的代码展示了这个库的基本使用场景: | ||
| 198 | + | ||
| 199 | +> [!WARNING] 使用时 import 的库名不变。 | ||
| 200 | + | ||
| 201 | +```javascript | ||
| 202 | +import React from 'react'; | ||
| 203 | +import { View, Alert, Button, StyleSheet } from 'react-native'; | ||
| 204 | +import Mailer from 'react-native-mail'; | ||
| 205 | + | ||
| 206 | +export default function App() { | ||
| 207 | + const handleEmail = () => { | ||
| 208 | + Mailer.mail( | ||
| 209 | + { | ||
| 210 | + subject: 'need help', | ||
| 211 | + recipients: ['support@example.com'], | ||
| 212 | + ccRecipients: ['supportCC@example.com'], | ||
| 213 | + bccRecipients: ['supportBCC@example.com'], | ||
| 214 | + body: '<b>A Bold Body</b>', | ||
| 215 | + isHTML: true, | ||
| 216 | + attachments: [ | ||
| 217 | + { | ||
| 218 | + // path 与 uri 二选一,指定附件数据所在的位置 | ||
| 219 | + path: '', // /data/storage/el2/base/haps/entry/files/11.png | ||
| 220 | + uri: '', // file://<packageName>/data/storage/el2/base/haps/entry/files/11.png | ||
| 221 | + // type 与 mimeType 二选一,指定数据的 MIME 类型 | ||
| 222 | + type: '', // jpg, png, doc, ppt, html, pdf, csv | ||
| 223 | + mimeType: '', // 仅在使用自定义类型时指定 | ||
| 224 | + name: '', // 可选:附件的自定义文件名 | ||
| 225 | + }, | ||
| 226 | + ], | ||
| 227 | + }, | ||
| 228 | + (error, event) => { | ||
| 229 | + if (error) { | ||
| 230 | + console.error('Send mail failed:', error); | ||
| 231 | + } else { | ||
| 232 | + console.error('Send mail success:', event); | ||
| 233 | + } | ||
| 234 | + } | ||
| 235 | + ); | ||
| 236 | + }; | ||
| 237 | + | ||
| 238 | + return ( | ||
| 239 | + <View style={styles.container}> | ||
| 240 | + <Button onPress={handleEmail} title="Email Me" color="#841584" /> | ||
| 241 | + </View> | ||
| 242 | + ); | ||
| 243 | +} | ||
| 244 | + | ||
| 245 | +const styles = StyleSheet.create({ | ||
| 246 | + container: { | ||
| 247 | + flex: 1, | ||
| 248 | + justifyContent: 'center', | ||
| 249 | + alignItems: 'center', | ||
| 250 | + backgroundColor: '#F1F3F5', | ||
| 251 | + }, | ||
| 252 | +}); | ||
| 253 | +``` | ||
| 254 | + | ||
| 255 | +## 使用说明 | ||
| 256 | + | ||
| 257 | +**发送邮件** | ||
| 258 | + | ||
| 259 | +```javascript | ||
| 260 | +import Mailer from 'react-native-mail'; | ||
| 261 | + | ||
| 262 | +Mailer.mail({ | ||
| 263 | + subject: 'need help', // 邮件主题 | ||
| 264 | + recipients: ['support@example.com'], // 收件人 | ||
| 265 | + ccRecipients: ['supportCC@example.com'], // 抄送人(可选) | ||
| 266 | + bccRecipients: ['supportBCC@example.com'], // 密送人(可选) | ||
| 267 | + body: '<b>A Bold Body</b>', // 邮件正文 | ||
| 268 | +}, (error, event) => { | ||
| 269 | + // 结果通过 callback 返回:error 为错误信息,event 为事件名称 | ||
| 270 | + if (error) { | ||
| 271 | + console.error('Send mail failed:', error); | ||
| 272 | + } | ||
| 273 | +}); | ||
| 274 | +``` | ||
| 275 | + | ||
| 276 | +**处理回调结果** | ||
| 277 | + | ||
| 278 | +```javascript | ||
| 279 | +Mailer.mail({ subject: 'need help', recipients: ['support@example.com'] }, (error, event) => { | ||
| 280 | + if (error) { | ||
| 281 | + console.error('Send mail failed:', error); | ||
| 282 | + } else { | ||
| 283 | + console.error('Send mail success:', event); | ||
| 284 | + } | ||
| 285 | +}); | ||
| 286 | +``` | ||
| 287 | + | ||
| 288 | +**发送 HTML 邮件与附件** | ||
| 289 | + | ||
| 290 | +```javascript | ||
| 291 | +Mailer.mail({ | ||
| 292 | + subject: '带附件的邮件', | ||
| 293 | + recipients: ['support@example.com'], | ||
| 294 | + body: '<b>A Bold Body</b>', | ||
| 295 | + isHTML: true, // 鸿蒙平台暂不支持 | ||
| 296 | + attachments: [ | ||
| 297 | + { | ||
| 298 | + path: '', // 与 uri 二选一:文件的绝对路径 | ||
| 299 | + uri: '', // 与 path 二选一:文件的 uri | ||
| 300 | + type: '', // 与 mimeType 二选一:jpg、png、doc、ppt、html、pdf、csv | ||
| 301 | + mimeType: '', // 与 type 二选一:自定义 MIME 类型 | ||
| 302 | + name: '', // 可选:附件自定义文件名 | ||
| 303 | + }, | ||
| 304 | + ], | ||
| 305 | +}, (error, event) => { | ||
| 306 | + console.log(error, event); | ||
| 307 | +}); | ||
| 308 | +``` | ||
| 309 | + | ||
| 310 | +> [!TIP] 鸿蒙平台暂不支持 `isHTML`、`attachments`、`customChooserTitle`,详见[遗留问题](#遗留问题)。 | ||
| 311 | + | ||
| 312 | +## 接口说明 | ||
| 313 | + | ||
| 314 | +> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。 | ||
| 315 | + | ||
| 316 | +> [!TIP] "OpenHarmony Support"列为 yes 表示 OpenHarmony平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 | ||
| 317 | + | ||
| 318 | +### API | ||
| 319 | + | ||
| 320 | +| Name | Description | Type | Required | Platform | HarmonyOS Support | | ||
| 321 | +| ---- | ---------------------------------------------------------------------------------- | -------------------------- | -------- | -------- | ----------------- | | ||
| 322 | +| mail | 拉起邮箱并向邮箱传递收件人、发件人、抄送人、密送人等信息,通过 callback 函数返回错误信息。 | Function(options,callback) | yes | all | yes | | ||
| 323 | + | ||
| 324 | +### 参数 | ||
| 325 | + | ||
| 326 | +#### Options | ||
| 327 | +| Name | Description | Type | Required | Platform | HarmonyOS Support | | ||
| 328 | +| ------------------ | ------------------- | -------- | -------- | -------- | ----------------- | | ||
| 329 | +| subject | 邮件主题 | string | no | all | yes | | ||
| 330 | +| recipients | 收件人 | string[] | no | all | yes | | ||
| 331 | +| ccRecipients | 抄送收件人 | string[] | no | all | yes | | ||
| 332 | +| bccRecipients | 密件抄送收件人 | string[] | no | all | yes | | ||
| 333 | +| body | 邮件内容 | string | no | all | yes | | ||
| 334 | +| customChooserTitle | 自定义选择器标题 | string | no | android | no | | ||
| 335 | +| isHTML | 邮件内容是否为 html | boolean | no | all | no | | ||
| 336 | +| attachments | 附件信息 | object[] | no | all | no | | ||
| 337 | + | ||
| 338 | +## 遗留问题 | ||
| 339 | + | ||
| 340 | +- [ ] 不支持 attachments 附件传递: [issue#1](https://github.com/react-native-oh-library/react-native-mail/issues/1) | ||
| 341 | +- [ ] 不支持 customChooserTitle: [issue#4](https://github.com/react-native-oh-library/react-native-mail/issues/4) | ||
| 342 | +- [x] 邮箱应用上 body 显示异常: [issue#2](https://github.com/react-native-oh-library/react-native-mail/issues/2) | ||
| 343 | +- [ ] 不支持 isHTML: [issue#7](https://github.com/react-native-oh-library/react-native-mail/issues/7) | ||
| 344 | + | ||
| 345 | +## 其他 | ||
| 346 | + | ||
| 347 | +> [!NOTE] 目前直接通过startAbility的方式直接跳转的是设备自带的电子邮件,所以不支持customChooserTitle自定义选择器标题。 | ||
| 348 | + | ||
| 349 | + | ||
| 350 | +## 目录结构 | ||
| 351 | + | ||
| 352 | +```` | ||
| 353 | +/rntpc_react-native-mail # 项目根目录 | ||
| 354 | +├── harmony # 鸿蒙适配代码 | ||
| 355 | +│ ├── mail.har # har 包 | ||
| 356 | +│ └── mail # 鸿蒙适配核心代码 | ||
| 357 | +│ ├── index.ets # 鸿蒙适配代码入口 | ||
| 358 | +│ ├── ts.ets # TurboModule ArkTS 声明入口 | ||
| 359 | +│ └── src/main | ||
| 360 | +│ ├── cpp # C++ 适配代码(MailPackage 及 codegen 生成代码) | ||
| 361 | +│ ├── ets # ArkTS 适配代码(RNMailPackage、RNMailTurboModule 等) | ||
| 362 | +│ └── module.json5 # 模块配置 | ||
| 363 | +├── src # RN 代码 | ||
| 364 | +│ └── NativeRNMail.harmonys.ts # TurboModule Spec 定义 | ||
| 365 | +├── example # 示例工程 | ||
| 366 | +├── index.js # 入口文件 | ||
| 367 | +├── index.d.ts # 类型定义 | ||
| 368 | +├── README.md # 中文安装使用方法 | ||
| 369 | +├── README_en.md # 英文安装使用方法 | ||
| 370 | +└── package.json # 包配置 | ||
| 371 | +```` | ||
| 372 | + | ||
| 373 | +## 贡献代码 | ||
| 374 | + | ||
| 375 | +使用过程中发现任何问题都可以提交 [Issue](https://gitcode.com/CPF-RN/rntpc_react-native-mail/issues),当然,也非常欢迎提交 [PR](https://gitcode.com/CPF-RN/rntpc_react-native-mail/pulls) 。 | ||
| 376 | + | ||
| 377 | +## 开源协议 | ||
| 378 | + | ||
| 379 | +本项目基于 [The MIT License (MIT)](https://github.com/chirag04/react-native-mail/blob/master/LICENSE) ,请自由地享受和参与开源。 | ||
| @@ -0,0 +1,380 @@ | |||
| 1 | +> Document Template: v0.4.2 | ||
| 2 | + | ||
| 3 | +<p align="center"> | ||
| 4 | + <h1 align="center"> <code>react-native-mail</code> </h1> | ||
| 5 | +</p> | ||
| 6 | + | ||
| 7 | +This project is based on [react-native-mail](https://github.com/chirag04/react-native-mail). | ||
| 8 | + | ||
| 9 | +This third-party library has been migrated to GitCode and is now available for direct download from npm. The new package name is: `@react-native-ohos/react-native-mail`. The version correspondence details are as follows: | ||
| 10 | + | ||
| 11 | +| Name | Version(Npm Address) | Release Information | Supported RN Version | Supported Autolink | Compile API Version | Community Baseline Version | Source code address | | ||
| 12 | +| --- | --- | --- | --- | --- | --- | --- |------------------------------------------------------------------------------------| | ||
| 13 | +| @react-native-ohos/react-native-mail | [~6.3.0 (In development)](https://www.npmjs.com/package/@react-native-ohos/react-native-mail) | [GitCode Releases](https://gitcode.com/CPF-RN/rntpc_react-native-mail/releases) | 0.82.* | Yes | API12+ | 6.1.1 | [master](https://gitcode.com/CPF-RN/rntpc_react-native-mail/tree/master) | | ||
| 14 | +| @react-native-ohos/react-native-mail | [~6.2.0 ](https://www.npmjs.com/package/@react-native-ohos/react-native-mail) | [GitCode Releases](https://gitcode.com/CPF-RN/rntpc_react-native-mail/releases) | 0.77.* | No | API12+ | 6.1.1 | [br_rnoh0.77](https://gitcode.com/CPF-RN/rntpc_react-native-mail/tree/br_rnoh0.77) | | ||
| 15 | +| @react-native-ohos/react-native-mail | [~6.1.2](https://www.npmjs.com/package/@react-native-ohos/react-native-mail) | [GitCode Releases](https://gitcode.com/CPF-RN/rntpc_react-native-mail/releases) | 0.72.* | Yes | API12+ | 6.1.1 | [br_rnoh0.72](https://gitcode.com/CPF-RN/rntpc_react-native-mail/tree/br_rnoh0.72) | | ||
| 16 | +| @react-native-oh-tpl/react-native-mail | [<= 6.1.1-0.0.1@deprecated](https://www.npmjs.com/package/@react-native-oh-tpl/react-native-mail) | [GitHub Releases(deprecated)](https://github.com/react-native-oh-library/react-native-mail/releases) | 0.72.* | No | API12+ | 6.1.1 | [sig](https://github.com/react-native-oh-library/react-native-mail/tree/sig) | | ||
| 17 | + | ||
| 18 | +## Introduction | ||
| 19 | + | ||
| 20 | +react-native-mail is a utility library used to open the email app and compose a new email.<br/> | ||
| 21 | + | ||
| 22 | +## Installation | ||
| 23 | + | ||
| 24 | +Go to the project directory and execute the following instruction: | ||
| 25 | + | ||
| 26 | +**npm** | ||
| 27 | + | ||
| 28 | +```bash | ||
| 29 | +npm install @react-native-ohos/react-native-mail | ||
| 30 | +``` | ||
| 31 | + | ||
| 32 | +**yarn** | ||
| 33 | + | ||
| 34 | +```bash | ||
| 35 | +yarn add @react-native-ohos/react-native-mail | ||
| 36 | +``` | ||
| 37 | + | ||
| 38 | +## Link | ||
| 39 | + | ||
| 40 | +| Version | Supported Autolink | Supported RN Version | | ||
| 41 | +| --- | --- |----------------------| | ||
| 42 | +| ~ 6.3.0 | Yes | 0.82 | | ||
| 43 | + | ||
| 44 | +Projects using AutoLink need to be configured according to this document. AutoLink framework guide: https://gitcode.com/CPF-RN/ohos_react_native/blob/main/docs/en/02-development/02-development-guide/autolinking.md | ||
| 45 | + | ||
| 46 | +If the version you are using supports Autolink and the project has integrated Autolink, you can skip the ManualLink configuration. | ||
| 47 | +<details> | ||
| 48 | + <summary>ManualLink: This step provides guidance for manually configuring native dependencies.</summary> | ||
| 49 | + | ||
| 50 | +Open the `harmony` directory of the HarmonyOS project in DevEco Studio. | ||
| 51 | + | ||
| 52 | +### 1. Overrides RN SDK | ||
| 53 | + | ||
| 54 | +To ensure the project relies on the same version of the RN SDK, add an `overrides` field in the project's root `oh-package.json5` file, specifying the RN SDK version to be used. The replacement version can be a specific version number, a semver range, or a locally available HAR package or source directory. | ||
| 55 | + | ||
| 56 | +For more information about this field, see the [official documentation](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/ide-oh-package-json5-V5#en-us_topic_0000001792256137_overrides). | ||
| 57 | + | ||
| 58 | +```json | ||
| 59 | +{ | ||
| 60 | + "overrides": { | ||
| 61 | + "@rnoh/react-native-openharmony": "~0.82.1" // ohpm version | ||
| 62 | + // "@rnoh/react-native-openharmony" : "./react_native_openharmony.har" // a locally available HAR package | ||
| 63 | + // "@rnoh/react-native-openharmony" : "./react_native_openharmony" // source code directory | ||
| 64 | + } | ||
| 65 | +} | ||
| 66 | +``` | ||
| 67 | + | ||
| 68 | +### 2. Introducing Native Code | ||
| 69 | + | ||
| 70 | +Currently, two methods are available: | ||
| 71 | + | ||
| 72 | +- Use the HAR file; | ||
| 73 | +- Directly link to the source code. | ||
| 74 | + | ||
| 75 | +Method 1 (recommended): Use the HAR file. | ||
| 76 | + | ||
| 77 | +> [!TIP] The HAR file is stored in the `harmony` directory in the installation path of the third-party library. | ||
| 78 | + | ||
| 79 | +Open `entry/oh-package.json5` and add the following dependency: | ||
| 80 | + | ||
| 81 | +```json | ||
| 82 | +"dependencies": { | ||
| 83 | + "@react-native-ohos/react-native-mail": "file:../../node_modules/@react-native-ohos/react-native-mail/harmony/mail.har" | ||
| 84 | + } | ||
| 85 | +``` | ||
| 86 | + | ||
| 87 | +Click the `sync` button in the upper right corner. | ||
| 88 | + | ||
| 89 | +Alternatively, run the following command on the terminal: | ||
| 90 | + | ||
| 91 | +```bash | ||
| 92 | +cd entry | ||
| 93 | +ohpm install | ||
| 94 | +``` | ||
| 95 | + | ||
| 96 | +Method 2: Directly link to the source code. | ||
| 97 | + | ||
| 98 | +> [!TIP] For details, see [Directly Linking Source Code](https://gitcode.com/CPF-RN/usage-docs/blob/master/en/link-source-code.md). | ||
| 99 | + | ||
| 100 | +### 3. Configuring CMakeLists and Introducing RNMailPackage | ||
| 101 | + | ||
| 102 | +Open `entry/src/main/cpp/CMakeLists.txt` and add: | ||
| 103 | + | ||
| 104 | +```diff | ||
| 105 | +project(rnapp) | ||
| 106 | +cmake_minimum_required(VERSION 3.4.1) | ||
| 107 | +set(CMAKE_SKIP_BUILD_RPATH TRUE) | ||
| 108 | +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") | ||
| 109 | +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") | ||
| 110 | ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") | ||
| 111 | +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp") | ||
| 112 | +set(LOG_VERBOSITY_LEVEL 1) | ||
| 113 | +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments") | ||
| 114 | +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie") | ||
| 115 | +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use | ||
| 116 | +add_compile_definitions(WITH_HITRACE_SYSTRACE) | ||
| 117 | + | ||
| 118 | +add_subdirectory("${RNOH_CPP_DIR}" ./rn) | ||
| 119 | + | ||
| 120 | +# RNOH_BEGIN: manual_package_linking_1 | ||
| 121 | +add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package) | ||
| 122 | ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-mail/src/main/cpp" ./mail) | ||
| 123 | +# RNOH_END: manual_package_linking_1 | ||
| 124 | + | ||
| 125 | +file(GLOB GENERATED_CPP_FILES "./generated/*.cpp") | ||
| 126 | + | ||
| 127 | +add_library(rnoh_app SHARED | ||
| 128 | + ${GENERATED_CPP_FILES} | ||
| 129 | + "./PackageProvider.cpp" | ||
| 130 | + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" | ||
| 131 | +) | ||
| 132 | +target_link_libraries(rnoh_app PUBLIC rnoh) | ||
| 133 | + | ||
| 134 | +# RNOH_BEGIN: manual_package_linking_2 | ||
| 135 | +target_link_libraries(rnoh_app PUBLIC rnoh_sample_package) | ||
| 136 | ++ target_link_libraries(rnoh_app PUBLIC rnoh_mail) | ||
| 137 | +# RNOH_END: manual_package_linking_2 | ||
| 138 | +``` | ||
| 139 | + | ||
| 140 | +Open `entry/src/main/cpp/PackageProvider.cpp` and add: | ||
| 141 | + | ||
| 142 | +```diff | ||
| 143 | +#include "RNOH/PackageProvider.h" | ||
| 144 | +#include "SamplePackage.h" | ||
| 145 | ++ #include "MailPackage.h" | ||
| 146 | + | ||
| 147 | +using namespace rnoh; | ||
| 148 | + | ||
| 149 | +std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) { | ||
| 150 | + return { | ||
| 151 | + std::make_shared<SamplePackage>(ctx), | ||
| 152 | ++ std::make_shared<MailPackage>(ctx) | ||
| 153 | + }; | ||
| 154 | +} | ||
| 155 | +``` | ||
| 156 | + | ||
| 157 | +### 4. Introducing RNMailPackage to ArkTS | ||
| 158 | + | ||
| 159 | +Open `entry/src/main/ets/RNPackagesFactory.ts` and add: | ||
| 160 | + | ||
| 161 | +```diff | ||
| 162 | + ... | ||
| 163 | ++ import {RNMailPackage} from '@react-native-ohos/react-native-mail/ts'; | ||
| 164 | + | ||
| 165 | +export function createRNPackages(ctx: RNPackageContext): RNPackage[] { | ||
| 166 | + return [ | ||
| 167 | ++ new RNMailPackage(ctx) | ||
| 168 | + ]; | ||
| 169 | +} | ||
| 170 | +``` | ||
| 171 | + | ||
| 172 | +</details> | ||
| 173 | + | ||
| 174 | +### Running | ||
| 175 | + | ||
| 176 | +Click the `sync` button in the upper right corner. | ||
| 177 | + | ||
| 178 | +Alternatively, run the following command on the terminal: | ||
| 179 | + | ||
| 180 | +```bash | ||
| 181 | +cd entry | ||
| 182 | +ohpm install | ||
| 183 | +``` | ||
| 184 | + | ||
| 185 | +Then build and run the project. | ||
| 186 | + | ||
| 187 | +## Constraints | ||
| 188 | + | ||
| 189 | +### Compatibility | ||
| 190 | + | ||
| 191 | +The content of this document has been verified based on the following versions: | ||
| 192 | + | ||
| 193 | +1. RNOH: 0.82.7; SDK: HarmonyOS 6.0.1 Release SDK; IDE: DevEco Studio 6.0.1.260; ROM: 6.0.0.130 SP15; | ||
| 194 | + | ||
| 195 | +## Usage Example | ||
| 196 | + | ||
| 197 | +The following code shows a basic usage scenario: | ||
| 198 | + | ||
| 199 | +> [!WARNING] The imported library name remains unchanged. | ||
| 200 | + | ||
| 201 | +```javascript | ||
| 202 | +import React from 'react'; | ||
| 203 | +import { View, Alert, Button, StyleSheet } from 'react-native'; | ||
| 204 | +import Mailer from 'react-native-mail'; | ||
| 205 | + | ||
| 206 | +export default function App() { | ||
| 207 | + const handleEmail = () => { | ||
| 208 | + Mailer.mail( | ||
| 209 | + { | ||
| 210 | + subject: 'need help', | ||
| 211 | + recipients: ['support@example.com'], | ||
| 212 | + ccRecipients: ['supportCC@example.com'], | ||
| 213 | + bccRecipients: ['supportBCC@example.com'], | ||
| 214 | + body: '<b>A Bold Body</b>', | ||
| 215 | + isHTML: true, | ||
| 216 | + attachments: [ | ||
| 217 | + { | ||
| 218 | + // Specify either `path` or `uri` to indicate where to find the file data. | ||
| 219 | + path: '', // /data/storage/el2/base/haps/entry/files/11.png | ||
| 220 | + uri: '', // file://<packageName>/data/storage/el2/base/haps/entry/files/11.png | ||
| 221 | + // Specify either `type` or `mimeType` to indicate the type of data. | ||
| 222 | + type: '', // Mime Type: jpg, png, doc, ppt, html, pdf, csv | ||
| 223 | + mimeType: '', // Use only if you want a custom type | ||
| 224 | + name: '', // Optional: custom filename for the attachment | ||
| 225 | + }, | ||
| 226 | + ], | ||
| 227 | + }, | ||
| 228 | + (error, event) => { | ||
| 229 | + if (error) { | ||
| 230 | + console.error('Send mail failed:', error); | ||
| 231 | + } else { | ||
| 232 | + console.error('Send mail success:', event); | ||
| 233 | + } | ||
| 234 | + } | ||
| 235 | + ); | ||
| 236 | + }; | ||
| 237 | + | ||
| 238 | + return ( | ||
| 239 | + <View style={styles.container}> | ||
| 240 | + <Button onPress={handleEmail} title="Email Me" color="#841584" /> | ||
| 241 | + </View> | ||
| 242 | + ); | ||
| 243 | +} | ||
| 244 | + | ||
| 245 | +const styles = StyleSheet.create({ | ||
| 246 | + container: { | ||
| 247 | + flex: 1, | ||
| 248 | + justifyContent: 'center', | ||
| 249 | + alignItems: 'center', | ||
| 250 | + backgroundColor: '#F1F3F5', | ||
| 251 | + }, | ||
| 252 | +}); | ||
| 253 | +``` | ||
| 254 | + | ||
| 255 | +## How to Use | ||
| 256 | + | ||
| 257 | +**Send an email** | ||
| 258 | + | ||
| 259 | +```javascript | ||
| 260 | +import Mailer from 'react-native-mail'; | ||
| 261 | + | ||
| 262 | +Mailer.mail({ | ||
| 263 | + subject: 'need help', // Email subject | ||
| 264 | + recipients: ['support@example.com'], // Recipients | ||
| 265 | + ccRecipients: ['supportCC@example.com'], // CC recipients (optional) | ||
| 266 | + bccRecipients: ['supportBCC@example.com'], // BCC recipients (optional) | ||
| 267 | + body: '<b>A Bold Body</b>', // Email body | ||
| 268 | +}, (error, event) => { | ||
| 269 | + // The result is returned via the callback: `error` is the error message and `event` is the event name | ||
| 270 | + if (error) { | ||
| 271 | + console.error('Send mail failed:', error); | ||
| 272 | + } | ||
| 273 | +}); | ||
| 274 | +``` | ||
| 275 | + | ||
| 276 | +**Handle the callback result** | ||
| 277 | + | ||
| 278 | +```javascript | ||
| 279 | +Mailer.mail({ subject: 'need help', recipients: ['support@example.com'] }, (error, event) => { | ||
| 280 | + if (error) { | ||
| 281 | + console.error('Send mail failed:', error); | ||
| 282 | + } else { | ||
| 283 | + console.error('Send mail success:', event); | ||
| 284 | + } | ||
| 285 | +}); | ||
| 286 | +``` | ||
| 287 | + | ||
| 288 | +**Send an HTML email with attachments** | ||
| 289 | + | ||
| 290 | +```javascript | ||
| 291 | +Mailer.mail({ | ||
| 292 | + subject: 'Mail with attachment', | ||
| 293 | + recipients: ['support@example.com'], | ||
| 294 | + body: '<b>A Bold Body</b>', | ||
| 295 | + isHTML: true, // Not supported on HarmonyOS yet | ||
| 296 | + attachments: [ | ||
| 297 | + { | ||
| 298 | + path: '', // Either `path` or `uri`: absolute path of the file | ||
| 299 | + uri: '', // Either `path` or `uri`: URI of the file | ||
| 300 | + type: '', // Either `type` or `mimeType`: jpg, png, doc, ppt, html, pdf, csv | ||
| 301 | + mimeType: '', // Either `type` or `mimeType`: custom MIME type | ||
| 302 | + name: '', // Optional: custom filename for the attachment | ||
| 303 | + }, | ||
| 304 | + ], | ||
| 305 | +}, (error, event) => { | ||
| 306 | + console.log(error, event); | ||
| 307 | +}); | ||
| 308 | +``` | ||
| 309 | + | ||
| 310 | +> [!TIP] `isHTML`, `attachments`, and `customChooserTitle` are not supported on HarmonyOS yet. See [Known Issues](#known-issues). | ||
| 311 | + | ||
| 312 | +## Available APIs | ||
| 313 | + | ||
| 314 | +> [!TIP] The **Platform** column indicates the platforms supported by the original third-party library. | ||
| 315 | + | ||
| 316 | +> [!TIP] If **OpenHarmony Platform Support** is **yes**, the OpenHarmony platform supports this property; **no** means not supported; **partially** means partially supported. Usage is consistent across platforms, and the effect aligns with iOS or Android. | ||
| 317 | + | ||
| 318 | + | ||
| 319 | +### API | ||
| 320 | + | ||
| 321 | +| Name | Description | Type | Required | Platform | HarmonyOS Support | | ||
| 322 | +| ---- | ---------------------------------------------------------------------------------- | -------------------------- | -------- | -------- | ----------------- | | ||
| 323 | +| mail | Launches the email app and passes information such as recipients, sender, and CC/BCC recipients to it, and returns error information through the callback function. | Function(options,callback) | yes | all | yes | | ||
| 324 | + | ||
| 325 | +### Parameters | ||
| 326 | + | ||
| 327 | +#### Options | ||
| 328 | +| Name | Description | Type | Required | Platform | HarmonyOS Support | | ||
| 329 | +| ------------------ | ------------------- | -------- | -------- | -------- | ----------------- | | ||
| 330 | +| subject | Email subject | string | no | all | yes | | ||
| 331 | +| recipients | Recipients | string[] | no | all | yes | | ||
| 332 | +| ccRecipients | CC recipients | string[] | no | all | yes | | ||
| 333 | +| bccRecipients | BCC recipients | string[] | no | all | yes | | ||
| 334 | +| body | Email body | string | no | all | yes | | ||
| 335 | +| customChooserTitle | Custom chooser title | string | no | android | no | | ||
| 336 | +| isHTML | Whether the email body is HTML | boolean | no | all | no | | ||
| 337 | +| attachments | Attachment information | object[] | no | all | no | | ||
| 338 | + | ||
| 339 | + | ||
| 340 | +## Known Issues | ||
| 341 | + | ||
| 342 | +- [ ] Passing attachments is not supported: [issue#1](https://github.com/react-native-oh-library/react-native-mail/issues/1) | ||
| 343 | +- [ ] customChooserTitle is not supported: [issue#4](https://github.com/react-native-oh-library/react-native-mail/issues/4) | ||
| 344 | +- [x] The body is displayed abnormally in the email app: [issue#2](https://github.com/react-native-oh-library/react-native-mail/issues/2) | ||
| 345 | +- [ ] isHTML is not supported: [issue#7](https://github.com/react-native-oh-library/react-native-mail/issues/7) | ||
| 346 | + | ||
| 347 | +## Other | ||
| 348 | + | ||
| 349 | +> [!NOTE] Currently, it jumps directly to the device's built-in email app through startAbility, so customChooserTitle is not supported. | ||
| 350 | + | ||
| 351 | +## Directory Structure | ||
| 352 | + | ||
| 353 | +```` | ||
| 354 | +/rntpc_react-native-mail # Project root directory | ||
| 355 | +├── harmony # HarmonyOS adaptation code | ||
| 356 | +│ ├── mail.har # HAR package | ||
| 357 | +│ └── mail # Core HarmonyOS adaptation code | ||
| 358 | +│ ├── index.ets # Adaptation code entry | ||
| 359 | +│ ├── ts.ets # TurboModule ArkTS declaration entry | ||
| 360 | +│ └── src/main | ||
| 361 | +│ ├── cpp # C++ adaptation code (MailPackage and codegen-generated code) | ||
| 362 | +│ ├── ets # ArkTS adaptation code (RNMailPackage, RNMailTurboModule, etc.) | ||
| 363 | +│ └── module.json5 # Module configuration | ||
| 364 | +├── src # React Native code | ||
| 365 | +│ └── NativeRNMail.harmonys.ts # TurboModule Spec definition | ||
| 366 | +├── example # Example project | ||
| 367 | +├── index.js # Entry file | ||
| 368 | +├── index.d.ts # Type definitions | ||
| 369 | +├── README.md # Chinese installation and usage guide | ||
| 370 | +├── README_en.md # English installation and usage guide | ||
| 371 | +└── package.json # Package configuration | ||
| 372 | +```` | ||
| 373 | + | ||
| 374 | +## How to Contribute | ||
| 375 | + | ||
| 376 | +If you find any problem when using react-native-share, submit an [issue](https://gitcode.com/CPF-RN/rntpc_react-native-mail/issues) or a [PR](https://gitcode.com/CPF-RN/rntpc_react-native-mail/pulls). | ||
| 377 | + | ||
| 378 | +## License | ||
| 379 | + | ||
| 380 | +This project is licensed under [The MIT License (MIT)](https://github.com/chirag04/react-native-mail/blob/master/LICENSE). Feel free to enjoy and contribute to open source. | ||
| @@ -8,7 +8,7 @@ | |||
| 8 | "start": "hdc rport tcp:8081 tcp:8081 && react-native start", | 8 | "start": "hdc rport tcp:8081 tcp:8081 && react-native start", |
| 9 | "codegen": "react-native codegen-harmony --rnoh-module-path ./harmony/entry/oh_modules/@rnoh/react-native-openharmony", | 9 | "codegen": "react-native codegen-harmony --rnoh-module-path ./harmony/entry/oh_modules/@rnoh/react-native-openharmony", |
| 10 | "pack:pkg": "cd ../ && npm pack && cd ./example", | 10 | "pack:pkg": "cd ../ && npm pack && cd ./example", |
| 11 | - "install:pkg": "npm uninstall @react-native-ohos/react-native-mail && npm run pack:pkg && npm i @react-native-ohos/react-native-mail@file:../react-native-ohos-react-native-mail-6.3.1-beta.1.tgz", | 11 | + "install:pkg": "npm uninstall @react-native-ohos/react-native-mail && npm run pack:pkg && npm i @react-native-ohos/react-native-mail@file:../react-native-ohos-react-native-mail-6.3.1-beta.2.tgz", |
| 12 | "dev": "npm run codegen && react-native bundle-harmony --dev --minify=false", | 12 | "dev": "npm run codegen && react-native bundle-harmony --dev --minify=false", |
| 13 | "prod": "npm run codegen && react-native bundle-harmony --dev=false --minify=true", | 13 | "prod": "npm run codegen && react-native bundle-harmony --dev=false --minify=true", |
| 14 | "postinstall": "node ./scripts/create-build-profile", | 14 | "postinstall": "node ./scripts/create-build-profile", |
| @@ -16,7 +16,7 @@ | |||
| 16 | }, | 16 | }, |
| 17 | "dependencies": { | 17 | "dependencies": { |
| 18 | "@gorhom/portal": "^1.0.14", | 18 | "@gorhom/portal": "^1.0.14", |
| 19 | - "@react-native-ohos/react-native-mail": "file:../react-native-ohos-react-native-mail-6.3.1-beta.1.tgz", | 19 | + "@react-native-ohos/react-native-mail": "file:../react-native-ohos-react-native-mail-6.3.1-beta.2.tgz", |
| 20 | "react": "19.1.1", | 20 | "react": "19.1.1", |
| 21 | "react-native": "0.82.1", | 21 | "react-native": "0.82.1", |
| 22 | "@rnoh/testerino": "npm:@react-native-oh-tpl/testerino@0.0.9", | 22 | "@rnoh/testerino": "npm:@react-native-oh-tpl/testerino@0.0.9", |
| @@ -1,7 +1,7 @@ | |||
| 1 | /** | 1 | /** |
| 2 | * Use these variables when you tailor your ArkTS code. They must be of the const type. | 2 | * Use these variables when you tailor your ArkTS code. They must be of the const type. |
| 3 | */ | 3 | */ |
| 4 | -export const HAR_VERSION = '6.3.1-beta.1'; | 4 | +export const HAR_VERSION = '6.3.1-beta.2'; |
| 5 | export const BUILD_MODE_NAME = 'debug'; | 5 | export const BUILD_MODE_NAME = 'debug'; |
| 6 | export const DEBUG = true; | 6 | export const DEBUG = true; |
| 7 | export const TARGET_NAME = 'default'; | 7 | export const TARGET_NAME = 'default'; |
| @@ -3,6 +3,6 @@ | |||
| 3 | * Use of this source code is governed by a MIT license that can be | 3 | * Use of this source code is governed by a MIT license that can be |
| 4 | * found in the LICENSE file. | 4 | * found in the LICENSE file. |
| 5 | */ | 5 | */ |
| 6 | -import { RNMailPackage } from './src/main/ets/RNMailPackge'; | 6 | +import { RNMailPackage } from './src/main/ets/RNMailPackage'; |
| 7 | export default RNMailPackage; | 7 | export default RNMailPackage; |
| 8 | export * from './ts'; | 8 | export * from './ts'; |
| @@ -1,6 +1,6 @@ | |||
| 1 | { | 1 | { |
| 2 | "name": "@react-native-ohos/react-native-mail", | 2 | "name": "@react-native-ohos/react-native-mail", |
| 3 | - "version": "6.3.1-beta.1", | 3 | + "version": "6.3.1-beta.2", |
| 4 | "description": "", | 4 | "description": "", |
| 5 | "main": "index.ets", | 5 | "main": "index.ets", |
| 6 | "author": "", | 6 | "author": "", |
| @@ -36,7 +36,7 @@ class Logger { | |||
| 36 | * @param Prefix Identifies the log tag. | 36 | * @param Prefix Identifies the log tag. |
| 37 | * @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF. | 37 | * @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF. |
| 38 | */ | 38 | */ |
| 39 | - constructor(prefix: string = 'MyApp', domain: number = 0xFF00, isDebug = false) { | 39 | + constructor(prefix: string = 'RNMail', domain: number = 0xFF00, isDebug = false) { |
| 40 | this.prefix = prefix; | 40 | this.prefix = prefix; |
| 41 | this.domain = domain; | 41 | this.domain = domain; |
| 42 | this.isDebug = isDebug; | 42 | this.isDebug = isDebug; |
| @@ -40,10 +40,14 @@ export class RNMailTurboModule extends TurboModule implements TM.RNMail.Spec { | |||
| 40 | mail({ subject= '', recipients=[], body='', ccRecipients=[], bccRecipients=[] }: mainOptions, callback: Function) { | 40 | mail({ subject= '', recipients=[], body='', ccRecipients=[], bccRecipients=[] }: mainOptions, callback: Function) { |
| 41 | let mailUri: string = ''; | 41 | let mailUri: string = ''; |
| 42 | mailUri += recipients?.join(',') || ''; | 42 | mailUri += recipients?.join(',') || ''; |
| 43 | - mailUri += '?cc=' + ccRecipients?.join(',') || ''; | 43 | + mailUri += '?subject=' + encodeURIComponent(subject); |
| 44 | - mailUri += '&bcc=' + bccRecipients?.join(',') || ''; | ||
| 45 | - mailUri += '&subject=' + subject; | ||
| 46 | mailUri += '&body=' + encodeURIComponent(body); | 44 | mailUri += '&body=' + encodeURIComponent(body); |
| 45 | + if (ccRecipients && ccRecipients.length > 0) { | ||
| 46 | + mailUri += '&cc=' + ccRecipients.join(','); | ||
| 47 | + } | ||
| 48 | + if (bccRecipients && bccRecipients.length > 0) { | ||
| 49 | + mailUri += '&bcc=' + bccRecipients.join(','); | ||
| 50 | + } | ||
| 47 | this.startEmailApp(mailUri, callback); | 51 | this.startEmailApp(mailUri, callback); |
| 48 | } | 52 | } |
| 49 | 53 | ||
| @@ -62,6 +66,7 @@ export class RNMailTurboModule extends TurboModule implements TM.RNMail.Spec { | |||
| 62 | this.ctx.uiAbilityContext.startAbility(want) | 66 | this.ctx.uiAbilityContext.startAbility(want) |
| 63 | .then(() => { | 67 | .then(() => { |
| 64 | Logger.info(TAG, 'startAbility success'); | 68 | Logger.info(TAG, 'startAbility success'); |
| 69 | + callback(null, 'sent'); | ||
【AI-Review】【一般】【基础代码问题】【代码逻辑错误】
● 问题: 第 69 行在 触发路径:
● 影响: JS 侧可能依据 ● 建议: 将事件名改为更准确的 ![]() ![]() | |||
| 65 | }) | 70 | }) |
| 66 | .catch((err: BusinessError) => { | 71 | .catch((err: BusinessError) => { |
| 67 | Logger.info(TAG, 'startAbility error.', err.message); | 72 | Logger.info(TAG, 'startAbility error.', err.message); |
| @@ -5,4 +5,4 @@ | |||
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | export * from './src/main/ets/RNMailTurboModule'; | 7 | export * from './src/main/ets/RNMailTurboModule'; |
| 8 | -export * from './src/main/ets/RNMailPackge'; | 8 | +export * from './src/main/ets/RNMailPackage'; |
| @@ -1,8 +1,11 @@ | |||
| 1 | { | 1 | { |
补充bug字段,files字段补充README_en.md ![]() ![]() | |||
| 2 | "name": "@react-native-ohos/react-native-mail", | 2 | "name": "@react-native-ohos/react-native-mail", |
| 3 | - "version": "6.3.1-beta.1", | 3 | + "version": "6.3.1-beta.2", |
| 4 | "description": "A wrapper on top of MFMailComposeViewController from iOS and Mail Intent on android and e-mail on harmony", | 4 | "description": "A wrapper on top of MFMailComposeViewController from iOS and Mail Intent on android and e-mail on harmony", |
| 5 | "homepage": "https://gitcode.com/CPF-RN/rntpc_react-native-mail#readme", | 5 | "homepage": "https://gitcode.com/CPF-RN/rntpc_react-native-mail#readme", |
| 6 | + "bugs": { | ||
| 7 | + "url": "https://gitcode.com/CPF-RN/rntpc_react-native-mail/issues" | ||
| 8 | + }, | ||
| 6 | "author": { | 9 | "author": { |
| 7 | "name": "Chirag Jain", | 10 | "name": "Chirag Jain", |
| 8 | "email": "jain_chirag04@yahoo.com", | 11 | "email": "jain_chirag04@yahoo.com", |
| @@ -26,6 +29,7 @@ | |||
| 26 | "index.js", | 29 | "index.js", |
| 27 | "!build", | 30 | "!build", |
| 28 | "README.md", | 31 | "README.md", |
| 32 | + "README_en.md", | ||
| 29 | "CHANGELOG.md", | 33 | "CHANGELOG.md", |
| 30 | "index.d.ts" | 34 | "index.d.ts" |
| 31 | ], | 35 | ], |


【AI-Review】【一般】【基础代码问题】【字符串问题】 ● 问题:
mail()函数对subject、body使用了encodeURIComponent编码(第 43、44 行),但新增的cc、bcc拼接逻辑(第 46、49 行)直接使用ccRecipients.join(',')和bccRecipients.join(',')拼入 mailto URI 的查询参数,未做任何 URI 编码。根据 RFC 6068,mailto URI 头字段值中的保留字符?、&、=必须进行百分号编码;而 RFC 5321 的 atext 允许邮箱本地部分(@ 之前)包含&、=、?、#等字符。当用户传入含这些字符的邮箱地址时,URI 会被错误解析。触发路径:
Mailer.mail({ ccRecipients: ['user&test@example.com'] }, cb);mail()执行第 46 行mailUri += '&cc=' + 'user&test@example.com',得到...&cc=user&test@example.com;startEmailApp第 60 行构造uri: 'mailto:...&cc=user&test@example.com';&test@example.com误认为另一个头字段,cc 实际只解析为user,而非user&test@example.com,收件人丢失。● 影响: 当 cc/bcc 收件人邮箱地址的本地部分含
&、=、?、#等 RFC 5321 允许的 atext 字符时,mailto URI 会被邮件应用错误解析,导致抄送/密送收件人丢失或错误;且与同函数内subject/body的编码处理不一致,本 PR 已修复subject编码却遗漏了 cc/bcc。● 建议: 对 cc/bcc 中的每个邮箱地址进行 URI 编码后再拼接,与
subject/body保持一致,例如:mailUri += '&cc=' + ccRecipients.map(e => encodeURIComponent(e)).join(',');(bcc 同理)。注:第 42 行recipients同样未编码,属历史遗留,建议一并评估。