HarmonyOS 跳转系统邮件,发送邮件的示例代码?

联系人信息中,如果对方提供邮箱,点击可以传递邮箱账号,直接跳转到系统邮箱

阅读 428
1 个回答

目前电子邮件可通过ability拉起,通过拼接uri传递参数

mail({ subject= '', recipients=[], body='', ccRecipients=[], bccRecipients=[] }: mainOptions, callback: Function) {
  let mailUri: string = '';
  mailUri += recipients?.join(',') || '';
  mailUri += '?cc=' + ccRecipients?.join(',') || '';
  mailUri += '&bcc=' + bccRecipients?.join(',') || '';
  mailUri += '&subject=' + subject;
  mailUri += '&body=' + body;
  Logger.info(TAG + 'mailUri ', mailUri, 'ccRecipients:' + ccRecipients, 'bccRecipients:' + bccRecipients);
  this.startEmailApp(mailUri, callback);
}
startEmailApp = (mailUri, callback) => {
  let want: Want = {
    bundleName: 'com.huawei.hmos.email',
    abilityName: 'EntryAbility',
    moduleName: 'entry',
    uri: 'mailto:' + mailUri,
    action: 'ohos.want.action.viewData',
  };
  Logger.info(TAG + 'want ', JSON.stringify(want));

  try {
    this.ctx.uiAbilityContext.startAbility(want)
      .then(() => {
        Logger.info(TAG, 'startAbility success');
      })
      .catch((err: BusinessError) => {
        Logger.info(TAG, 'startAbility error.', err.message);
        callback(err.message);
      })
  } catch (e) {
    callback(e);
    Logger.info(TAG + 'error:', e);
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
logo
HarmonyOS
子站问答
访问
宣传栏