1# Using mailto to Start an Email Application 2 3## When to Use 4 5You can create hyperlinks that link to email addresses through mailto, so that users can easily access email clients by touching the hyperlinks present within websites or applications. You can also preset the recipient, subject, and body of the email in the mailto: fields to save the time when composing emails. 6 7Typical development scenarios are as follows: 8 9- On websites: 10 - When browsing product pages on a shopping website, users can touch a **Contact Us** button, which triggers the default email client with the customer service email pre-filled as the recipient and the subject line set to inquire about the product. 11 - On job posting pages, touching an **Apply for Job** button opens an email client with the recruitment email address pre-filled, the subject line set to "Request for a Specific Position," and the body possibly pre-populated with a request template. 12- Within applications: 13 - In a mobile application, touching a **Feedback** button may cause the application to activate the system's default email client, with the feedback email address and issue details preset. 14 - In a mobile application, when users touch a **Share via email** button, the application can use the mailto protocol to initiate the email client, pre-populating the subject and body of the email. 15 16## Format of mailto 17 18The standard mailto format is as follows: 19 20``` 21mailto:someone@example.com?key1=value1&key2=value2 22``` 23 24+ **mailto:**: mailto scheme, which is mandatory. 25+ **someone@example.com**: recipient address, which is optional. If there are multiple addresses, separate them with commas (,). 26+ **?**: start character of the email header declaration. If email header parameters are contained, this parameter is mandatory. 27+ **key-value**: email header parameters. For details, see the following table. 28 29 | Email Header Parameter| Description| Data Type| Mandatory| 30 | --- | --- | --- | --- | 31 | subject | Email subject.| string | No| 32 | body | Email body.| string | No| 33 | cc| Copy-to person. Use commas (,) to separate multiple recipients.| string | No| 34 | bcc| Bcc recipient. Use commas (,) to separate multiple recipients.| string | No| 35 36## Developing a Caller Application 37 38### On Websites 39 40Hyperlinks on web pages must comply with the mailto protocol. Example: 41 42 43``` 44<a href="mailto:support@example.com?subject=Product Inquiry&body=I am interested in...">Contact Us</a> 45``` 46Replace the email address with the actual one, and configure the email content as required. 47 48### Within Applications 49 50Pass the mailto string to the **uri** parameter. In the application, the context can be obtained through **getContext (this)** for a page and through **this.context** for an ability. 51 52```ts 53@Entry 54@Component 55struct Index { 56 57 build() { 58 Column() { 59 Button('Feedback') 60 .onClick(() => { 61 let ctx = getContext(this) as common.UIAbilityContext; 62 ctx.startAbility({ 63 action: 'ohos.want.action.sendToData', 64 uri: 'mailto:feedback@example.com?subject=App Feedback&body=Please describe your feedback here...' 65 }) 66 67 }) 68 } 69 } 70} 71``` 72 73 74 75## Developing a Target Application 76 771. To be started by other applications in mailto mode, an application must declare its mailto configuration in the [module.json5 file](../quick-start/module-configuration-file.md). 78 79 ```json 80 { 81 "module": { 82 // ... 83 "abilities": [ 84 { 85 // ... 86 "skills": [ 87 { 88 "actions": [ 89 'ohos.want.action.sendToData' 90 ], 91 "uris": [ 92 { 93 "scheme": "mailto", 94 // linkFeature is used to start a vertical domain panel. 95 "linkFeature": 'ComposeMail' 96 } 97 ] 98 } 99 ] 100 } 101 ] 102 } 103 } 104 ``` 105 1062. The target application obtains the **uri** parameter from the code for parsing. 107 108 ```ts 109 export default class EntryAbility extends UIAbility { 110 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 111 // Callback of the application cold start lifecycle, where other services are processed. 112 parseMailto(want); 113 } 114 115 onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { 116 // Callback of the application hot start lifecycle, where other services are processed. 117 parseMailto(want); 118 } 119 120 public parseMailto(want: Want) { 121 const uri = want?.uri; 122 if (!uri || uri.length <= 0) { 123 return; 124 } 125 // Start to parse mailto... 126 } 127 } 128 129 ``` 130