Josh-CO Dev

Solving the worlds problems one line of code at a time.

Sending Emails from Silverlight

Leave a comment


One of the requirements of my application I am writing is to send emails upon the creation of a new comment. This turned out to be quite simple. I am using RIA services and a Domain Service. In my domain service, I simply added the following code. I have noticed that this does not seem to work through GoDaddy, but it does test fine from my machine.

[Invoke]
public string SendEmail(string to, string body, string subject)
{
try
{
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress(to));
msg.From = new MailAddress(“noreply@josh-co.com”);
msg.Body = body;
msg.Subject = subject;
SmtpClient smtp = new SmtpClient();
smtp.Host = “smtp.gmail.com”;
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential(“gmailaccount”, “gmailpassword”);
smtp.Port = 587;
smtp.Send(msg);
return “Success”;
}
catch (Exception ex)
{
return ex.ToString();
}
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s