Carlos Rodrigez Carlos Rodrigez - 2 months ago 16
C# Question

How can you send an email to another users email without opening the mail? Xamarin Forms

I am building an app in Xamarin Forms where you can buy products etc. Now I am at the stage where I want to send the user a confirmation when their order has been placed.

I have a string cointaining their email but I am not quite sure how to proceed. When I have previously worked with mail it looks something like this:

Device.OpenUri(new Uri(" candy&body=you can trust me"));

And what this does is that you open your own mail and you have to send it yourself to yourself which obviously is wrong.

So my question is, how can I send a confirmation email from my email to their inputted email which I have stored in a string?


You have a few options. If your email is a Microsoft Exchange mailbox, you can use Exchange Web Services (EWS), which is fairly simple if you follow code samples online. Otherwise, you should use an SMTP client. .NET has its own that you can include: System.Net.Mail, or you can find a number of libraries online.

If you're inclined toward the .NET SMTP option, I would take a look at this question. It has a fairly complete example that should help you get started.

EDIT: You mentioned that your backend is PHP-Based. There are plenty of SMTP libraries for PHP as well and plenty of code samples. Here's another SO question I'd suggest you look at to help you get started in PHP instead of C#.