1e41f4b71Sopenharmony_ci# Starting an Email Application
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThis topic describes how to open the vertical domain panel of email applications.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci## Parameters on the Email Application Panel
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciIf the **type** field in **startAbilityByType** is set to **mail**, **wantParam** contains the following properties.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci| Name                             | Description                                  | Data Type| Mandatory                  |
10e41f4b71Sopenharmony_ci| ------------------------------------- | -------------------------------------- | -------- | -------------------------- |
11e41f4b71Sopenharmony_ci| email                                 | Email address of the recipient. Multiple email addresses, separated by commas (,), are supported.| string[ ] | No                        |
12e41f4b71Sopenharmony_ci| cc                                    | Email address of the CC recipient. Multiple email addresses, separated by commas (,), are supported.| string[ ] | No                        |
13e41f4b71Sopenharmony_ci| bcc                                   | Email address of the BCC recipient. Multiple email addresses, separated by commas (,), are supported.| string[ ] | No                        |
14e41f4b71Sopenharmony_ci| subject                               | Email subject.                              | string   | No                        |
15e41f4b71Sopenharmony_ci| body                                  | Email body.                              | string   | No                        |
16e41f4b71Sopenharmony_ci| ability.params.stream                 | Email attachments (URI list of the attachments).         | string[ ] | No                        |
17e41f4b71Sopenharmony_ci| ability.want.params.uriPermissionFlag | At least the read permission must be granted on the email attachments.              | [wantConstant.Flags](../reference/apis-ability-kit/js-apis-app-ability-wantConstant.md#wantconstantflags)   | Mandatory when an email attachment exists.|
18e41f4b71Sopenharmony_ci| sceneType                             | 1: Send an email.                  | number   | No. When this parameter is left unspecified, the default value **1** is used.                        |
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci> **NOTE**
21e41f4b71Sopenharmony_ci>
22e41f4b71Sopenharmony_ci> * Parameters of the string type displayed in the vertical domain panel of email applications must be encoded using **encodeURI**.
23e41f4b71Sopenharmony_ci> 
24e41f4b71Sopenharmony_ci> * For parameters of the string[] type displayed in the vertical domain panel of email applications, all elements in the array must be encoded using **encodeURI**.
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci## Developing a Caller Application
27e41f4b71Sopenharmony_ci1. Import the **ohos.app.ability.common** module.
28e41f4b71Sopenharmony_ci    ```ts
29e41f4b71Sopenharmony_ci    import { common, wantConstant } from '@kit.AbilityKit';
30e41f4b71Sopenharmony_ci    ```
31e41f4b71Sopenharmony_ci2. Construct parameters and call the **startAbilityByType** API.
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci    ```ts
34e41f4b71Sopenharmony_ci    let context = getContext(this) as common.UIAbilityContext;
35e41f4b71Sopenharmony_ci    let wantParam: Record<string, Object> = {
36e41f4b71Sopenharmony_ci      'sceneType': 1,
37e41f4b71Sopenharmony_ci      'email': [encodeURI('xxx@example.com'),encodeURI('xxx@example.com')], // Email address of the recipient. Multiple values are separated by commas (,). The array content is URL encoded using encodeURI().
38e41f4b71Sopenharmony_ci      'cc': [encodeURI('xxx@example.com'),encodeURI('xxx@example.com')], // Email address of the CC recipient. Multiple values are separated by commas (,). The array content is URL encoded using encodeURI().
39e41f4b71Sopenharmony_ci      'bcc': [encodeURI('xxx@example.com'),encodeURI('xxx@example.com')], // Email address of the BCC recipient. Multiple values are separated by commas (,). The array content is URL encoded using encodeURI().
40e41f4b71Sopenharmony_ci      'subject': encodeURI('Email subject'), // Email subject. The content is URL encoded using encodeURI().
41e41f4b71Sopenharmony_ci      'body': encodeURI('Email body'), // Email body. The content is URL encoded using encodeURI().
42e41f4b71Sopenharmony_ci      'ability.params.stream':[encodeURI('attachment uri1'),encodeURI('attachment uri2')], // Attachment URIs. Multiple values are separated by commas (,). The array content is URL encoded using encodeURI().
43e41f4b71Sopenharmony_ci      'ability.want.params.uriPermissionFlag': wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION
44e41f4b71Sopenharmony_ci    };
45e41f4b71Sopenharmony_ci    let abilityStartCallback: common.AbilityStartCallback = {
46e41f4b71Sopenharmony_ci      onError: (code: number, name: string, message: string) => {
47e41f4b71Sopenharmony_ci        console.log(`onError code ${code} name: ${name} message: ${message}`);
48e41f4b71Sopenharmony_ci      },
49e41f4b71Sopenharmony_ci      onResult: (result)=>{
50e41f4b71Sopenharmony_ci        console.log(`onResult result: ${JSON.stringify(result)}`);
51e41f4b71Sopenharmony_ci      }
52e41f4b71Sopenharmony_ci    }
53e41f4b71Sopenharmony_ci    
54e41f4b71Sopenharmony_ci    context.startAbilityByType("mail", wantParam, abilityStartCallback, 
55e41f4b71Sopenharmony_ci        (err) => {
56e41f4b71Sopenharmony_ci            if (err) {
57e41f4b71Sopenharmony_ci                console.error(`startAbilityByType fail, err: ${JSON.stringify(err)}`);
58e41f4b71Sopenharmony_ci            } else {
59e41f4b71Sopenharmony_ci                console.log(`success`);
60e41f4b71Sopenharmony_ci            }
61e41f4b71Sopenharmony_ci    });
62e41f4b71Sopenharmony_ci    ```
63e41f4b71Sopenharmony_ci    Effect
64e41f4b71Sopenharmony_ci    
65e41f4b71Sopenharmony_ci    ![Effect example](./figures/start-mail-panel.png)
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci## Developing a Target Application
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci1. Add the [linkFeature](../quick-start/module-configuration-file.md#skills) attribute to **module.json5** and declare the features supported. In this way, the system can find the applications that support a specific feature from all the applications installed on the device.
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci    | Value          | Description                     |
72e41f4b71Sopenharmony_ci    | --------------| ------------------------- |
73e41f4b71Sopenharmony_ci    | ComposeMail   | The application supports email writing.	|
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci    ```json
76e41f4b71Sopenharmony_ci    {
77e41f4b71Sopenharmony_ci      "abilities": [
78e41f4b71Sopenharmony_ci          {
79e41f4b71Sopenharmony_ci          "skills": [
80e41f4b71Sopenharmony_ci              {
81e41f4b71Sopenharmony_ci              "uris": [
82e41f4b71Sopenharmony_ci                  {
83e41f4b71Sopenharmony_ci                  "scheme": "mailto", // It is for reference only. Ensure that the declared URI can be started by external systems.
84e41f4b71Sopenharmony_ci                  "host": "",
85e41f4b71Sopenharmony_ci                  "path": "",
86e41f4b71Sopenharmony_ci                  "linkFeature": "ComposeMail" // Declare that the application supports email writing.
87e41f4b71Sopenharmony_ci                  }
88e41f4b71Sopenharmony_ci                ]
89e41f4b71Sopenharmony_ci              }
90e41f4b71Sopenharmony_ci          ]
91e41f4b71Sopenharmony_ci          }
92e41f4b71Sopenharmony_ci      ]
93e41f4b71Sopenharmony_ci    }
94e41f4b71Sopenharmony_ci    ```
95e41f4b71Sopenharmony_ci    
96e41f4b71Sopenharmony_ci2. Parse and process the parameters transferred from the panel.
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci    ```ts
99e41f4b71Sopenharmony_ci    UIAbility::onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void
100e41f4b71Sopenharmony_ci    ```
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci    The **want.parameters** parameter contains the following parameters, which may be slightly different from the ones passed in by the caller.
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci    | Name            | Description                                                        | Data Type| Mandatory|
105e41f4b71Sopenharmony_ci    | -------------------- | ------------------------------------------------------------ | -------- | -------- |
106e41f4b71Sopenharmony_ci    | email  | Email address of the recipient. Multiple email addresses, separated by commas (,), are supported.                                 | string[ ] | No|
107e41f4b71Sopenharmony_ci    | cc | Email address of the CC recipient. Multiple email addresses, separated by commas (,), are supported.                                 | string[ ] | No|
108e41f4b71Sopenharmony_ci    | bcc    | Email address of the BCC recipient. Multiple email addresses, separated by commas (,), are supported.                                 | string[ ] | No |
109e41f4b71Sopenharmony_ci    | subject    | Email subject.                              | string   | No |
110e41f4b71Sopenharmony_ci    | body   | Email body.                            | string | No |
111e41f4b71Sopenharmony_ci    | stream | Email attachments (URI list of the attachments).                 | string[ ] | No |
112e41f4b71Sopenharmony_ci    
113e41f4b71Sopenharmony_ci    > **NOTE**
114e41f4b71Sopenharmony_ci    > 
115e41f4b71Sopenharmony_ci    > * Parameters of the string type received by the target application must be decoded using **decodeURI**.
116e41f4b71Sopenharmony_ci    > 
117e41f4b71Sopenharmony_ci    > * For parameters of the string[] type received by the target application, all elements in the array must be decoded using **decodeURI**.
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci**Sample Code**
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci```ts
122e41f4b71Sopenharmony_ciimport { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
123e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
124e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI';
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ciconst TAG = 'MailTarget1.EntryAbility'
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility {
129e41f4b71Sopenharmony_ci    windowStage: window.WindowStage | null = null;
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci    email: string[] | undefined;
132e41f4b71Sopenharmony_ci    cc: string[] | undefined;
133e41f4b71Sopenharmony_ci    bcc: string[] | undefined;
134e41f4b71Sopenharmony_ci    subject: string | undefined;
135e41f4b71Sopenharmony_ci    body: string | undefined;
136e41f4b71Sopenharmony_ci    stream: string[] | undefined;
137e41f4b71Sopenharmony_ci    
138e41f4b71Sopenharmony_ci    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
139e41f4b71Sopenharmony_ci        hilog.info(0x0000, TAG, `onCreate, want=${JSON.stringify(want)}`);
140e41f4b71Sopenharmony_ci        super.onCreate(want, launchParam);
141e41f4b71Sopenharmony_ci        this.parseWant(want);
142e41f4b71Sopenharmony_ci    }
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci    onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
145e41f4b71Sopenharmony_ci        hilog.info(0x0000, TAG, `onNewWant, want=${JSON.stringify(want)}`);
146e41f4b71Sopenharmony_ci        super.onNewWant(want, launchParam);
147e41f4b71Sopenharmony_ci        this.parseWant(want);
148e41f4b71Sopenharmony_ci        if (!this.windowStage) {
149e41f4b71Sopenharmony_ci            hilog.error(0x0000, TAG, 'windowStage is null');
150e41f4b71Sopenharmony_ci            this.context.terminateSelf();
151e41f4b71Sopenharmony_ci            return;
152e41f4b71Sopenharmony_ci        }
153e41f4b71Sopenharmony_ci        this.loadPage(this.windowStage);
154e41f4b71Sopenharmony_ci    }
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci    private parseWant(want: Want): void {
157e41f4b71Sopenharmony_ci        this.email = this.decodeStringArr(want.parameters?.email as string[]);
158e41f4b71Sopenharmony_ci        this.cc = this.decodeStringArr(want.parameters?.cc as string[]);
159e41f4b71Sopenharmony_ci        this.bcc = this.decodeStringArr(want.parameters?.bcc as string[]);
160e41f4b71Sopenharmony_ci        this.subject = decodeURI(want.parameters?.subject as string); // Use decodeURI() to decode the URL of the email subject. Other fields are processed in the same way.
161e41f4b71Sopenharmony_ci        this.body = decodeURI(want.parameters?.body as string); // Use decodeURI() to decode the URL of the email body. Other fields are processed in the same way.
162e41f4b71Sopenharmony_ci        this.stream = this.decodeStringArr(want.parameters?.stream as string[]);
163e41f4b71Sopenharmony_ci    }
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci    // Use decodeURI() to decode the content in the string array.
166e41f4b71Sopenharmony_ci    private decodeStringArr(source: string[] | undefined): string[] {
167e41f4b71Sopenharmony_ci        let target: string[] = [];
168e41f4b71Sopenharmony_ci        source?.forEach(e => {
169e41f4b71Sopenharmony_ci            target.push(decodeURI(e));
170e41f4b71Sopenharmony_ci        })
171e41f4b71Sopenharmony_ci        return target;
172e41f4b71Sopenharmony_ci    }
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci    private loadPage(windowStage: window.WindowStage): void {
175e41f4b71Sopenharmony_ci        const storage: LocalStorage = new LocalStorage({
176e41f4b71Sopenharmony_ci            "email": this.email,
177e41f4b71Sopenharmony_ci            "cc": this.cc,
178e41f4b71Sopenharmony_ci            "bcc": this.bcc,
179e41f4b71Sopenharmony_ci            "subject": this.subject,
180e41f4b71Sopenharmony_ci            "body": this.body,
181e41f4b71Sopenharmony_ci            "stream": this.stream
182e41f4b71Sopenharmony_ci        } as Record<string, Object>);
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci        windowStage.loadContent('pages/ComposeMailPage', storage);
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci    }
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci    onDestroy(): void {
189e41f4b71Sopenharmony_ci        hilog.info(0x0000, TAG, `onDestroy`);
190e41f4b71Sopenharmony_ci    }
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci    onWindowStageCreate(windowStage: window.WindowStage): void {
193e41f4b71Sopenharmony_ci        hilog.info(0x0000, TAG, `onWindowStageCreate`);
194e41f4b71Sopenharmony_ci        this.windowStage = windowStage;
195e41f4b71Sopenharmony_ci        this.loadPage(this.windowStage);
196e41f4b71Sopenharmony_ci    }
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci    onWindowStageDestroy(): void {
199e41f4b71Sopenharmony_ci        hilog.info(0x0000, TAG, `onWindowStageDestroy`);
200e41f4b71Sopenharmony_ci    }
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci    onForeground(): void {
203e41f4b71Sopenharmony_ci        hilog.info(0x0000, TAG, `onForeground`);
204e41f4b71Sopenharmony_ci    }
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ci    onBackground(): void {
207e41f4b71Sopenharmony_ci        hilog.info(0x0000, TAG, `onBackground`);
208e41f4b71Sopenharmony_ci    }
209e41f4b71Sopenharmony_ci}
210e41f4b71Sopenharmony_ci```
211