question

BruceKrueger-2659 avatar image
0 Votes"
BruceKrueger-2659 asked BruceKrueger-2659 commented

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



 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 = "mobile@sacerveceros.org";
         List<string> recipients = new List<string>();
         public EmailTest()
         {
             InitializeComponent();
             recipients.Add("mobile@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);
         }
     }
 }


dotnet-xamarin
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I get the error in Android project and I have made the appropriate insert into the AndroidManifest.xml file.

0 Votes 0 ·

1 Answer

LeonLu-MSFT avatar image
1 Vote"
LeonLu-MSFT answered BruceKrueger-2659 commented

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.


· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Can you install an email client into the Debug Android Device Manager?
I found the email client in the Android Device Emulator.

0 Votes 0 ·
LeonLu-MSFT avatar image LeonLu-MSFT BruceKrueger-2659 ·

Can you download email client (outlook or Gmail) from google play store? By default, if you use android emulator to make a test, Gmail is installed by default.

0 Votes 0 ·

I opened the email client in the phone emulator and added an account.
Now I get Specified method is not supported.
Is this just an emulator problem and It will work on an actual phone?

0 Votes 0 ·
LeonLu-MSFT avatar image LeonLu-MSFT BruceKrueger-2659 ·

Is this just an emulator problem and It will work on an actual phone?

No, I test it in emulator, but my emulator installs with google play store like this following thread and login an account in Gmail.

https://docs.microsoft.com/en-us/xamarin/android/get-started/installation/android-emulator/device-manager-images/win/09-new-device-editor.png#lightbox

0 Votes 0 ·
LeonLu-MSFT avatar image LeonLu-MSFT BruceKrueger-2659 ·

Do you check your emulator that installed google play store? Or test it in physical android device, is that worked? If it still not work, can you share a mini demo that I can reproduce this issue?

0 Votes 0 ·

Thanks for your help.
It works fine in the emulator after I created a new device with Google Play Store and Google API's.

0 Votes 0 ·