Silverlight 5 Hosting :: How to Send Email (Yahoo! SMTP) with Silverlight 5 WCF RIA

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

Comments are closed.

Sponsors

JaringanHosting.com

Cheap Reseller Hosting

Best Blog Hosting Provider

Best European ASP.NET 4.0 Hosting Provider