Hello,
Can I send an email using Xamarin.Forms without user interaction? I tried using System.Net.Mail and MailKit and both are not working in xamarin.forms. MailKit cannot be added as a nuget package in the main project but can be added in the IOS and Android projects separately. Can I use an API for sending emails with the indie license? Any other alternatives?
Thank you.
I'm not sure if you'll find anything that "just works" in Xamarin.Forms. But if you found a library like MailKit that works on Android and iOS, then you can use an interface + dependency injection or a service locator to make it work in a Xamarin.Forms PCL. The built-in DependencyService has a good guide here: https://developer.xamarin.com/guides/xamarin-forms/dependency-service/introduction/, in case you decide to go that route.
Another option would be to just implement the mail stuff in a web service that sends the actual mails and call that. That way you're independent of the user and their devices.
Answers
Maybe you can find something here
https://forums.xamarin.com/discussion/19756/send-email-from-shared-code-in-xamarin-forms
I'm not sure if you'll find anything that "just works" in Xamarin.Forms. But if you found a library like MailKit that works on Android and iOS, then you can use an interface + dependency injection or a service locator to make it work in a Xamarin.Forms PCL. The built-in DependencyService has a good guide here: https://developer.xamarin.com/guides/xamarin-forms/dependency-service/introduction/, in case you decide to go that route.
@AlessandroCaliaro,
I've already checked it before, did not find it helpful as I don't want users to send emails I want emails to be sent automatically. Also the last 3 or 4 replies in that forum concerning sending emails automatically weren't very helpful.
Thank you anyway.
@Sturgmeister
Thank you for the answer. I was thinking of going to that route but didn't know how. Seems like the only option available. I will check the the guide now, thank you.
Another option would be to just implement the mail stuff in a web service that sends the actual mails and call that. That way you're independent of the user and their devices.
Are you absolutely sure you want SMTP in your application? You should carefully rethink this nightmare.
How will you prevent abuse?
How will you handle bounces?
What about compliance with the new DMARC rules?
What SMTP settings will the app use, and are you willing to support your users so they can configure this?
What if they're connected via WIFI to a provider that blocks port 25 (as most do now)?
I got around these headaches by using a web service and put my email functionality server-side
@devnl
I would go with the other solution only because I'm not familiar with how to create a web service and call it. If you could provide me with an example or a link I would be grateful. Thanks
@RobertHudson.9525, I was not really aware of all these problems, thank you for pointing them out. Like I just asked @devnl, would you please provide me with an example or a link explaining how to create a web service and call it using xamarin.forms? Thanks in advance.
@ZeyadAtef ,
Can check with SMTP. I already integrated in one of my application.
MailMessage message = new System.Net.Mail.MailMessage();
string toEmail = ToAddress;
message.From = new MailAddress(fromEmail);
message.To.Add(toEmail);
message.Subject = Subject;
message.Body = MsgBody;
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
Keep in mind that sendgrid.net is not free.
Hi , i was trying send email with xam.plugins.messaging . but emailMessenger.CanSendEmail is always showing false
var emailMessenger = MessagingPlugin.EmailMessenger;
try {
if (emailMessenger.CanSendEmail)
{
// Send simple e-mail to single receiver without attachments, bcc, cc etc.
emailMessenger.SendEmail("[email protected]", "Xamarin Messaging Plugin", "Well hello there from Xam.Messaging.Plugin");
Hope i can get solved on this .. tnx in advance .....
Can I know How can we use SMTP for automatically sending Email? Is it better way to use SMTP to send Email Automatically.Thank You
Ok guys, I just checked some differents solutions because I have the same need to send email from my app.
Now, after some times to evaluate the situation, trying some components available in nuget or github, I can tell that there is almost 1 solution that works for sure.
Briefly:
1. Mailkit doesn't work for me, it immediately crashes when creating an object of MimeMessage type on Android.
2. Seems that Messaging Plugin for Xamarin and Windows is only able to send email using the default client of OS, and this is not my requirement
3. Using the standard System.Net.Mail namespace works good for me: I tested it successfully both from Android and iOS, it doesn't require any specific platform implementation, and it works good using standard authentication (on port 25) and also with SSL (only if the server support implicit SSL, tipically on port 587 like gmail)
@Caioshinn - Could you please share the code which you coded using System.Net.Mail namespace. Appreciate your quick response in this regard.