In a Windows Forms project, I used the SmtpClient and MailMessage class in order to send information by email.
Is there an equivalent for Windows Phone 8?
In a Windows Forms project, I used the SmtpClient and MailMessage class in order to send information by email.
Is there an equivalent for Windows Phone 8?
You can use Microsoft.Phone.Tasks.EmailComposeTask
to compose an e-mail using the inbuilt mail client:
var task = new EmailComposeTask {To = email};
task.Show();
Alternately you can post data to a 3rd party service, such as SendGrid
to send the e-mail via an API.
There are no SMTP APIs available on Windows Phone.
It's really simple! This is from MSDN:
First you should add:
using Microsoft.Phone.Tasks;
to your code, and then for personalizing and going to the mail app add this:
EmailComposeTask emailComposeTask = new EmailComposeTask();
emailComposeTask.Subject = "message subject";
emailComposeTask.Body = "message body";
emailComposeTask.To = "recipient@example.com";
emailComposeTask.Cc = "cc@example.com";
emailComposeTask.Bcc = "bcc@example.com";
emailComposeTask.Show();
You need to use sharing
functionality. It will allow you to create an email template (set subject, body, recipient, etc) and open it to the user, so he or she could just click "send". There's no such thing as smtp client, for better or worse. Here's a nice description of your options to send something from Windows Phone 8.
You can also use the third party library LiveMailMesage. You have to pay for it, but it will allow you to send emails without launching the EmailComposeTask. It will also let you add attachments and things like that if you need.
If you are developing a Universal WinRT Windows Phone application, you could use the Windows.ApplicationModel.Email.EmailMessage
namespace as the Microsoft.Phone.Tasks.EmailComposeTask
namespace doesn't work on WinRT application.
Then, uses this code to create and launch a new email.
// Create your new email message.
var em = new EmailMessage() ;
// Add as much EmailRecipient in it as you need using the following method.
em.To.Add(new EmailRecipient("yourname@yourdomain.com"));
em.Subject = "Your Subject...";
em.Body = "Your email body...";
// You can add an attachment that way.
//em.Attachments.Add(new EmailAttachment(...);
// Show the email composer.
await EmailManager.ShowComposeNewEmailAsync(em);
As far as i search about this no System.Net.Mail is not available in Windows Phone
For many other cases (especially feedback forms) you may better off connecting to a dedicated web service rather than detouring through email.
And if you're writing an email client and specifically need to connect to the mail server then there isn't anything in box so you'll either need to connect to a service specific API (many modern mail services support REST clients) or implement SMTP yourself.
It will be easy to create an API to send Json to server and the SMTP will be configured over there.