简体   繁体   English

如何从Windows Phone 8应用程序发送电子邮件?

[英]How do I send an email from a Windows Phone 8 application?

In a Windows Forms project, I used the SmtpClient and MailMessage class in order to send information by email. 在Windows Forms项目中,我使用SmtpClient和MailMessage类来通过电子邮件发送信息。

Is there an equivalent for Windows Phone 8? Windows Phone 8是否具有等效功能?

You can use Microsoft.Phone.Tasks.EmailComposeTask to compose an e-mail using the inbuilt mail client: 您可以使用Microsoft.Phone.Tasks.EmailComposeTask使用内置的邮件客户端编写电子邮件:

  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. 或者,您可以将数据发布到第三方服务(例如SendGrid以通过API发送电子邮件。

There are no SMTP APIs available on Windows Phone. Windows Phone上没有可用的SMTP API。

It's really simple! 真的很简单! This is from MSDN : 这是从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. 您需要使用sharing功能。 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. 不论好坏,都没有smtp客户程序。 Here 'sa nice description of your options to send something from Windows Phone 8. 是对您从Windows Phone 8发送内容的选项的很好描述。

You can also use the third party library LiveMailMesage . 您还可以使用第三方库LiveMailMesage You have to pay for it, but it will allow you to send emails without launching the EmailComposeTask. 您必须为此付费,但是它将使您无需启动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. 如果要开发通用WinRT Windows Phone应用程序,则可以使用Windows.ApplicationModel.Email.EmailMessage命名空间,因为Microsoft.Phone.Tasks.EmailComposeTask命名空间在WinRT应用程序上不起作用。

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 据我搜索有关此信息,Windows Phone中没有System.Net.Mail。

For many other cases (especially feedback forms) you may better off connecting to a dedicated web service rather than detouring through email. 对于许多其他情况(尤其是反馈表单),您最好连接到专用的Web服务,而不要绕过电子邮件绕行。

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. 而且,如果您正在编写电子邮件客户端,并且特别需要连接到邮件服务器,那么框中没有任何内容,因此您需要连接到特定于服务的API(许多现代邮件服务都支持REST客户端)或实施SMTP自己。

It will be easy to create an API to send Json to server and the SMTP will be configured over there. 创建API将Json发送到服务器很容易,并且SMTP将在该服务器上进行配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Windows Phone 7应用程序发送电子邮件 - How to send email from windows phone 7 application 如何从WinRT / Windows应用商店应用程序发送电子邮件? - How do I send an email from a WinRT/Windows Store application? 如何在Windows Phone 7中设置或确认电子邮件帐户以从我的发送邮件应用程序发送邮件 - How to set-up or confirm email account to sent email from my send mail application in Windows Phone 7 如何使用from字段在Windows Phone 8上使用C#发送电子邮件 - How to send email with C# on Windows Phone 8 with from field 从Windows Phone 8.1发送电子邮件 - Send email from windows phone 8.1 使用自定义凭据从Windows Phone 8发送电子邮件 - Send Email from windows phone 8 with custom credentials 如何从Windows Phone 7向.NET Winform应用程序发送推送通知 - How to send a Push Notification from windows Phone 7 to .NET Winform Application 如何从Windows Phone应用程序发送带有代理地址的HttpWebRequest - How to send a HttpWebRequest with proxy address from Windows phone application 如何从Windows Phone 7应用程序将数据发送到Web服务 - how to send data to web service from windows phone 7 application 从Windows Phone 7应用程序发送电子邮件 - Sending email from Windows Phone 7 application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM