Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Sent Email (Yahoo! SMTP) with Silverlight 5 WCF RIA

0.00/5 (No votes)
27 Mar 2012 1  
How to sent email (Yahoo! SMTP) with Silverlight 5 WCF RIA.

Introduction

I just want to share my own code to sent emails in Silverlight 5. I hope it can help other developers to sent emails easily.

Using the code

I will go straight to the code. Just include this code in your Web Services:

public partial class GeneralDomainService : LinqToSqlDomainService<BabyPinkMallLinqDataContext>
{
    [Invoke]
    public void SendEmail(string subject, string text, string toAddress, string fromAddress)
    {
        MailMessage message = new MailMessage();
        
        SmtpClient server = new SmtpClient("smtp.mail.yahoo.com",587);
        server.EnableSsl = false;
        server.UseDefaultCredentials = false;
        server.Credentials = 
          new NetworkCredential("yourEmail@yahoo.com", "yourpassword");
        message.From = new MailAddress(fromAddress);
        message.Subject = subject;
        message.Body = text;
        message.IsBodyHtml = true;
        message.To.Add(new MailAddress(toAddress));
        server.Timeout = 5000;
        server.Send(message);
    }
}

and you can call it from your view like this:

YourDomainContext.SendEmail("Subject", "textBody", "ToAddress", "fromAddress");

Points of Interest

I used Invoke as an attribute because this method doesn't need any result. Just sent an e-mail to your customer.(^o^)v

*I'm so sorry if my writing isn't very good. This is my first time sharing code. Thanks.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here