Mail Composer
Once after importing the name space, you can send a mail with MailComposer class.
You can set the following to the MailComposer.
  • To Recipients
  • Cc Recipients
  • Bcc Recipients
  • Subject
  • Body
  • Screenshot/Image
  • Attachment (any file)
Before accessing any of the MailComposer features you need to check if it's allowed to send mails through mail client apps on the user's device.
1
bool canSendMail = MailComposer.CanSendMail();
Copied!
Once you get the results from above methods, you need to add content to the mail composer based on the above status.

Send a text mail

1
MailComposer composer = MailComposer.CreateInstance();
2
composer.SetToRecipients(new string[1]{"[email protected]"});
3
composer.SetCcRecipients(new string[1]{"[email protected]"});
4
composer.SetBccRecipients(new string[1]{"[email protected]"});
5
6
composer.SetSubject("Subject");
7
composer.SetBody("Body", false);//Pass true if string is html content
8
composer.SetCompletionCallback((result, error) => {
9
Debug.Log("Mail composer was closed. Result code: " + result.ResultCode);
10
});
11
composer.Show();
Copied!

Send a mail with screenshot

1
MailComposer composer = MailComposer.CreateInstance();
2
composer.SetToRecipients(new string[1]{"[email protected]"});
3
composer.SetCcRecipients(new string[1]{"[email protected]"});
4
composer.SetBccRecipients(new string[1]{"[email protected]"});
5
6
composer.SetSubject("Subject");
7
composer.SetBody("Body", false);//Pass true if string is html content
8
composer.AddScreenshot("screenshot file name");
9
composer.SetCompletionCallback((result, error) => {
10
Debug.Log("Mail composer was closed. Result code: " + result.ResultCode);
11
});
12
composer.Show();
Copied!

Send a mail with an attachment

1
MailComposer composer = MailComposer.CreateInstance();
2
composer.SetToRecipients(new string[1]{"[email protected]"});
3
composer.SetCcRecipients(new string[1]{"[email protected]"});
4
composer.SetBccRecipients(new string[1]{"[email protected]"});
5
6
composer.SetSubject("Subject");
7
composer.SetBody("Body", false);//Pass true if string is html content
8
composer.AddAttachment(fileByteData, mimeType, "file name");//fileByteData => file data bytes
9
composer.SetCompletionCallback((result, error) => {
10
Debug.Log("Mail composer was closed. Result code: " + result.ResultCode);
11
});
12
composer.Show();
Copied!
It's allowed to add multiple attachments!
Last modified 11mo ago