public static string SendEmail(KitsuneConvertMailRequest req) { try { var request = (HttpWebRequest)WebRequest.Create(EmailAPI); request.Method = "POST"; request.ContentType = "application/json"; var jsonSerializer = new DataContractJsonSerializer(typeof(KitsuneConvertMailRequest)); var mem = new MemoryStream(); jsonSerializer.WriteObject(mem, req); string finalData = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length); var bytes = new UTF8Encoding().GetBytes(finalData); using (Stream stream = request.GetRequestStream()) { stream.Write(bytes, 0, bytes.Length); } WebResponse ws = request.GetResponse(); var sr = new StreamReader(ws.GetResponseStream()); var rs = sr.ReadToEnd(); return(rs); } catch (Exception ex) { return(null); //EventLogger.Write(ex, "NowFloats.Boost Exception: Unable to SendMailToServer", null); } }
public static bool SendContactFormEmail(string domain, Dictionary <string, string> pair, string url) { try { //get the user mail id var userEmail = MongoHelper.GetCustomerEmailAsync(domain); //create the mail object string data = String.Empty; foreach (var key in pair) { data = data + key + ":" + pair + "<br/><br/>"; } String subject = "New inquiry via website"; String emailBody = "Hi, <br/> You have a received the following inquiry:<br/>" + data; var requestObj = new KitsuneConvertMailRequest { ClientId = ClientId, EmailBody = emailBody, Subject = subject, To = new List <string> { } }; //send customer enquiry details to the user APIHelper.SendEmail(requestObj); return(true); } catch (Exception ex) { // EventLogger.Write(ex, "Error in Submitform",requestUrl:url); } return(false); }
//mails public string SendEmail(EmailRequestWithAttachments req, EmailUserConfigType configType = EmailUserConfigType.WEBSITE_DEVELOPER, string clientId = null) { try { var basePlugin = BasePluginConfigGenerator.GetBasePlugin(clientId); var basePluginEmailConfiguration = (configType == EmailUserConfigType.WEBSITE_DEVELOPER) ? basePlugin.GetEmailConfiguration() : basePlugin.GetKAdminEmailConfiguration(); WithFloatsExternalSMTPConfiguration smtpConfig; #region INIT EMAIL CONFIGURATION if (req.CustomSMTPConfig == null) { smtpConfig = new WithFloatsExternalSMTPConfiguration() { EnableSsl = basePluginEmailConfiguration.EnableSsl, ServerHost = basePluginEmailConfiguration.ServerHost, ServerPort = basePluginEmailConfiguration.ServerPort, SMTPUserName = basePluginEmailConfiguration.SMTPUserName, SMTPUserPassword = basePluginEmailConfiguration.SMTPUserPassword, TimeOut = basePluginEmailConfiguration.TimeOut, UserName = basePluginEmailConfiguration.SMTPUserName }; } else { smtpConfig = new WithFloatsExternalSMTPConfiguration() { EnableSsl = req.CustomSMTPConfig.EnableSsl, ServerHost = req.CustomSMTPConfig.ServerHost, ServerPort = req.CustomSMTPConfig.ServerPort, SMTPUserName = req.CustomSMTPConfig.SMTPUserName, SMTPUserPassword = req.CustomSMTPConfig.SMTPUserPassword, TimeOut = req.CustomSMTPConfig.TimeOut, UserName = req.CustomSMTPConfig.UserName }; } #endregion var request = (HttpWebRequest)WebRequest.Create(EnvConstants.Constants.EmailAPI); request.Method = "POST"; request.ContentType = "application/json"; var requestObj = new KitsuneConvertMailRequest { ClientId = EnvConstants.Constants.KitsuneDevClientId, EmailBody = req.EmailBody, Subject = req.Subject, To = req.To, Attachments = req.Attachments, From = basePluginEmailConfiguration.FromEmailAddress, CustomSMTPConfig = smtpConfig }; var jsonSerializer = new DataContractJsonSerializer(typeof(KitsuneConvertMailRequest)); var mem = new MemoryStream(); jsonSerializer.WriteObject(mem, requestObj); string finalData = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length); var bytes = new UTF8Encoding().GetBytes(finalData); using (Stream stream = request.GetRequestStream()) { stream.Write(bytes, 0, bytes.Length); } WebResponse ws = request.GetResponse(); var sr = new StreamReader(ws.GetResponseStream()); var rs = sr.ReadToEnd(); return(rs); } catch (Exception ex) { return(null); //EventLogger.Write(ex, "NowFloats.Boost Exception: Unable to SendMailToServer", null); } }