Why am I gettting Error "Specified Method is not supported" when trying to send email?

Bruce Krueger 331 Reputation points
2022-05-25T22:19:46.907+00:00
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Xamarin.Essentials;

namespace SACerveceros
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class EmailTest : ContentPage
    {
        string subject = "subjecttest";
        string body = "bodytest";
        string recipientemailaddress = "******@sacerveceros.org";
        List<string> recipients = new List<string>();
        public EmailTest()
        {
            InitializeComponent();
            recipients.Add("******@sacerveceros.org");
            LabelEmail.Text = "Recipient: " + recipientemailaddress;
            LabelSubject.Text = "Subject: " + subject;
            LabelBody.Text = "Body: " + body;
        }

        private async Task SendEmail(string subject, string body, List<string> recipients)
        {
            try
            {
                var message = new EmailMessage
                {
                    Subject = subject,
                    Body = body,
                    To = recipients,
                };
                await Email.ComposeAsync(message);
            }
            catch (FeatureNotSupportedException fbsEx)
            {
                LabelError.Text = fbsEx.Message;
            }
            catch (Exception ex)
            {
                LabelError.Text = "Error: " + ex.Message;
            }
        }


        public void RecipientEmailaddress_Completed(object sender, EventArgs e)
        {
            recipientemailaddress = ((Entry)sender).Text;
            recipients.Add(recipientemailaddress);
            LabelEmail.Text = "Recipient: " + recipientemailaddress;

        }
        private void EmailSubject_Completed(object sender, EventArgs e)
        {
            subject = null;
            subject = ((Entry)sender).Text;
            LabelSubject.Text = "Subject: " + subject;
        }
        private void Emailbody_Completed(object sender, EventArgs e)
        {
            body += ((Entry)sender).Text;
            LabelBody.Text = "Body: " + body;
        }
        private void EnterButton_Clicked(object sender, EventArgs e)
        {
            LabelEmail.Text = "Recipient: " + recipientemailaddress;
            LabelSubject.Text = "Subject: " + subject;
            LabelBody.Text = "Body: " + body;
            SendEmail(subject, body, recipients);
        }
    }
}
Developer technologies .NET Xamarin
{count} votes

Accepted answer
  1. Anonymous
    2022-05-26T03:06:03.617+00:00

    Hello,​

    I tried your code and I add <queries> tags to <manifest> tag in AndroidManifest.xml, it worked and will invoke email client to send a email.

    If there is no email client installed that exception is thrown and expected. So please install email client in your device such as Outlook, etc.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.