Recently I'm programming in Xamarin.forms and I have an App that by pressing a button you have to send an e-mail to a predefined email.
Searching the internet I found the NuGet Xam.Plugins.Messaging
which works, but that makes the App open to send the mail (For example: gmail) and what I need is that the mail is sent directly without having to go through for an App previously.
Is there such a possibility?
Here I leave what the button does:
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Plugin.Messaging;
namespace PruebaCorreo
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Chat : ContentPage
{
public Chat()
{
InitializeComponent();
}
private void BtnMail_Clicked(object sender, EventArgs e)
{
var emailTask = CrossMessaging.Current.EmailMessenger;
if (emailTask.CanSendEmail)
{
// Envia un correo simple.
emailTask.SendEmail("[email protected]", "Asunto", "Cuerpo del mail");
// Envia un correo con mas datos.
var email = new EmailMessageBuilder()
.To("[email protected]")
.Cc("[email protected]")
.Subject("Asunto del correo")
.Body("Este es el cuerpo del correo")
.Build();
emailTask.SendEmail(email);
}
}
}
}