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

前端 未结 6 2119
忘了有多久
忘了有多久 2020-12-16 15:38

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?

6条回答
  •  感情败类
    2020-12-16 16:01

    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);
    

提交回复
热议问题