Nopster
Nopster

Reputation: 97

How send email with attachment in windows universall app

How can i send an email with attachment in windows universal app (windows phone 8.1 and windows 8.1)

Class Windows.ApplicationModel.Email.EmailMessage is available only for windows phone

Upvotes: 2

Views: 1767

Answers (3)

Hassaan
Hassaan

Reputation: 35

You can use SMTP for sending email in windows 8:

SmtpMail oMail = new SmtpMail("TryIt");
oSmtp = new SmtpClient();
oMail.From = new MailAddress("[email protected]");
oMail.To.Add(new MailAddress("[email protected]"));
oMail.Subject = "Subject ";
oMail.TextBody = "Here is body";
SmtpServer oServer = new SmtpServer("smtp.gmail.com");
oServer.User = "[email protected]";
oServer.Password = "123456";
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
await oSmtp.SendMailAsync(oServer, oMail);

Upvotes: 0

Rob Caplan - MSFT
Rob Caplan - MSFT

Reputation: 21899

There is no direct, in-box way to send an email in a Windows Store app.

As you note, Windows.ApplicationModel.Email is available only for Windows Phone Runtime apps. This is one of the discontinuities in Universal apps where a feature is available on one platform but not both.

Options are:

  • Use the share contract rather than explicitly forcing email. This is the preferred method in general, although there are specific cases for which it doesn't work
  • Connect to a web service. This is often the best solution for feedback since the app can provide a custom form and doesn't have to push the user through an external app. You could also use a web service which will forward to email on the server side.
  • Connect to the mail server directly and implement SMTP, POP, IMAP, etc. This is generally best for service specific apps which can expose their own share target.
  • Not relevant for your case, but if you didn't need the attachment you could launch a mailto: URI

Upvotes: 3

Greenhorn
Greenhorn

Reputation: 74

You could use MailMessage email = new MailMessage(); from System.Net.Mail-Namesapce

Upvotes: 0

Related Questions