SMTP Configuration Service

Discussion in 'Getting started' started by seal, May 14, 2012.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Please see the article:

    http://www.silverlightnext.com/2010/06/send-email-from-silverlight-application.html

    I am using this procedure to get Silverlight email to work.

    First I define a class SLEmailMessage

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Runtime.Serialization;

    namespace SealSplash.Web.ServiceObjects
    {
    [DataContract]
    public class SLEmailMessage
    {
    [DataMember]
    public string To { get; set; }

    [DataMember]
    public string From { get; set; }

    [DataMember]
    public string Subject { get; set; }

    [DataMember]
    public string Body { get; set; }

    }

    In Web Config I have
    <system.net>
    <mailSettings>
    <smtp deliveryMethod="Network" from="[email protected]">
    <network host="localhost"
    port="25"
    defaultCredentials="true"
    password="password"
    userName="[email protected]" />
    </smtp>
    </mailSettings>
    </system.net>

    (I have also tried host="smtp.sealbeachimagelab.com" and
    host="www.sealbeachimagelab.com")


    Now write the sending code in service class:
    using System;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    using SealSplash.Web.ServiceObjects;
    using System.Net.Mail;

    namespace SealSplash.Web.Services
    {
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class EmailService
    {
    [OperationContract]
    public bool SendEmail(SLEmailMessage emailMessage)
    {
    bool isEmailSendSuccessfully = false;
    try
    {
    MailMessage mailMessage = new MailMessage(emailMessage.From, emailMessage.To);
    mailMessage.Subject = emailMessage.Subject;
    mailMessage.Body = emailMessage.Body;
    SmtpClient smtp = new SmtpClient();
    smtp.Send(mailMessage);
    isEmailSendSuccessfully = true;
    }
    catch { isEmailSendSuccessfully = false; }
    return isEmailSendSuccessfully;
    }
    }
    }

    I have also added Service Reference in Solution Explorer.
    EmailserviceReference

    Here is the code to activate the email service

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using SealSplash.EmailServiceReference;
    using System.Diagnostics;


    private void SendEmail(object sender, RoutedEventArgs e)
    {
    EmailServiceClient emailClient = new EmailServiceClient();
    emailClient.SendEmailCompleted += new EventHandler<SendEmailCompletedEventArgs>(emailClient_SendEmailCompleted);

    txtstatus.Text = "Text:Sendemail starting";
    SLEmailMessage emailMessage = new SLEmailMessage
    {
    To = "[email protected]",
    From = "[email protected]",
    Subject = "Email from Silverlight app.",
    Body = "This email is send from a Silverlight application for testing"
    };
    emailClient.SendEmailAsync(emailMessage);
    txtstatus.Text = "Sendemail done";
    return;
    }

    This is not working. I am doing the email send, but I get no response back.
    How do I debug service software?

    How to add email Silverlightm support?
    http://www.sealbeachimagelab.com/sealsplash/
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    Try send it to your own email rather than Yahoo. Yahoo has a very strict spam filtering and its well know for them to "eat" legit email.

    This is especially the case since you are using a Yahoo from address.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page