Exemplo n.º 1
0
        /// <summary>
        /// Send Email Notification to Requester with attachment
        /// </summary>
        /// <param name="objEMailDac"></param>
        public static void SendBookingRequestNotificationTo_Requester_Attachment(EmailNotificationModel objEMailDac, string senderEmailId, string attachment_path)
        {
            var client = new SmtpClient
            {
                DeliveryMethod = SmtpDeliveryMethod.Network,
                //EnableSsl = true,//for local it should true
                EnableSsl = false,//For Production it shpuld false
                Host      = objEMailDac.SmtpServer,
                Port      = Convert.ToInt32(objEMailDac.SmtpPort),
            };
            var credentials = new NetworkCredential(objEMailDac.SmtpUser, objEMailDac.SmtpPass);

            client.UseDefaultCredentials = false;
            client.Credentials           = credentials;
            var body = objEMailDac.TemplateFilePath;
            var msg  = new MailMessage
            {
                From       = new MailAddress(objEMailDac.SmtpUser),
                IsBodyHtml = true,
                Subject    = objEMailDac.EmailSubjectName,
                Body       = body,
            };

            msg.Attachments.Add(new Attachment(attachment_path));
            msg.To.Add(senderEmailId);
            try
            {
                client.Send(msg);
            }
            catch (Exception ex)
            {
                ErrorLog.AddEmailLogg(ex);
                return;
            }
        }
Exemplo n.º 2
0
        public static void SendBookingRequestNotificationTo_InCC(EmailNotificationModel objEMailDac, string senderEmailId, string[] senderEmailIdCC)
        {
            string[] senderEmailIds   = new string[] { senderEmailId };
            string[] senderEmailIdCCs = senderEmailIdCC;

            string MailApi         = ConfigurationManager.AppSettings["MailApi"];
            var    _jsonSerialiser = new JavaScriptSerializer();
            var    _jsonRequest    = _jsonSerialiser.Serialize
                                         (new Mail()
            {
                applicationKey   = ConfigurationManager.AppSettings["MailApiKey"],
                cc               = senderEmailIdCCs,
                from             = objEMailDac.SmtpUser,
                plainTextContent = string.Empty,
                htmlContent      = objEMailDac.TemplateFilePath.Trim(),
                subject          = objEMailDac.EmailSubjectName,
                to               = senderEmailIds
            }
                                         );

            try
            {
                var s = SendEmailThroughAPI(MailApi, _jsonRequest);
            }
            catch (Exception ex)
            {
                ErrorLog.AddEmailLogg(ex);
                return;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Send Email Through API Method
        /// </summary>
        /// <param name="MailApiUrl"></param>
        /// <param name="jRequest"></param>
        /// <returns></returns>
        public static bool SendEmailThroughAPI(string MailApiUrl, string jRequest)
        {
            bool result = false;

            try
            {
                using (WebClient _proxy = new WebClient())
                {
                    _proxy.Headers.Add("Content-Type", "application/json");
                    _proxy.Encoding = System.Text.Encoding.UTF8;
                    var _response = _proxy.UploadString(MailApiUrl, "POST", jRequest);
                    if (_response.Contains("200"))
                    {
                        result = true;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLog.AddEmailLogg(ex);
                return(result);
            }
            return(result);
        }