+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Emails are not getting delivered.

Emails are not getting delivered.

2 posts, 0 answered
  1. Dev_91
    Dev_91 avatar
    2 posts
    Registered:
    17 Nov 2012
    14 Mar 2014
    Link to this post

    Hi,

     I am developing the Email sending code for one of my WCF service in project. The code is as followed:

    [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, UriTemplate = "/CommonServices/LocationService.svc/Send")]
            public string SendCarrerFormEmailConfirmation(CarrerFormViewModel _carrerFormData)
            {
                string strResult = "";
                try
                {
     
                    string fromEmail = "";
                    EmailData _email = new EmailData();
     
                    _email.EmailSubject = "Loan Centers – Careers";
                    _email.EmailBody = "This is Email Body";
     
                    var dynamicModuleManager = DynamicModuleManager.GetManager();
                    Type showcaseType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.AdminSettings.AdminParameters");
     
                    // This is how we get the collection of ContentPage items
                    var showcases = dynamicModuleManager.GetDataItems(showcaseType).Where("ParameterName == @0", "CareerFormAdminEmail").Where(s => s.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live);
                     
                    _email.ToEmailID = "testdev@website.co.in";
                    if(showcases.Any())
                    {
                       _email.ToEmailID = showcases.FirstOrDefault().GetValue("ParameterValue").ToString();
                    }
     
     
                    var manager = ConfigManager.GetManager();
                    var smtpSettings = Config.Get<SystemConfig>().SmtpSettings;
                    MailMessage message = new MailMessage();
     
                    message.From = new MailAddress(smtpSettings.UserName);
                    message.To.Add(new MailAddress(_email.ToEmailID));
     
                    message.Subject = _email.EmailSubject;
                    message.Body = _email.EmailBody;
                    message.IsBodyHtml = true;
                    message.BodyEncoding = Encoding.Unicode;
                    message.SubjectEncoding = Encoding.Unicode;
     
                    //The below code is not working for Sending Emails
                    EmailSender.Get().Send(message);
     
                    //mark as sent ok
                    strResult = "Sucess";
                }
                catch { strResult = "Error"; }
                return strResult;
            }
     

    On line  EmailSender.Get().Send(message);  there is no error/exception, but Email is not Delivered.

    I have Set the SMTP Credentials as mentioned on site's tutorials.

     



    If I debug the code It contains all the SMTP Info (It's correct & working fine in my other website).

     

    Also, If you could help me about how to Access this WCF service using JavaScript Ajax, as By using JavaScript Ajax I am getting error in post method/ but in Get Method I can access other Services.

    Thanks

     

  2. Ivan D. Dimitrov
    Ivan D. Dimitrov avatar
    310 posts
    Registered:
    26 Mar 2015
    18 Mar 2014
    Link to this post
    Hi,

    Can you please try the following code in order to send your e-mails:
    var manager = ConfigManager.GetManager();
               
            
               string smtpHost = manager.GetSection<SystemConfig>().SmtpSettings.Host;
               int smtpPort = manager.GetSection<SystemConfig>().SmtpSettings.Port;
               var smtpClient = new SmtpClient(smtpHost, smtpPort);
               
               var message =
                   new MailMessage("soma@mail.com", "ivand.dimitrov@telerik.com")
                   {
                       Subject = "Hi",
                       Body = "test"
                   };
               smtpClient.Send(message);

    It will take all of your configurations directly and provided your backend smtp settings are correct, the code will send a message.

    Regards,
    Ivan D. Dimitrov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
2 posts, 0 answered