Пример #1
0
        //HRMS_DATBASEEntities db = new HRMS_DATBASEEntities();
        public emailProperty Emailsetting(string Setting_ID)
        {
            emailProperty ob = new emailProperty();

            ob.E_Credentials_UserName = "******";
            ob.E_Credentials_Password = "******";
            ob.E_Smtp_Client          = "intjmrp.com";
            ob.E_Port                  = 25;
            ob.E_EnableSsl             = true;
            ob.E_Timeout               = 100000;
            ob.E_DeliveryMethod        = "SmtpDeliveryMethod.Network";
            ob.E_UseDefaultCredentials = false;
            ob.E_Delivery_Notification = "DeliveryNotificationOptions.OnFailure";


            return(ob);
        }
Пример #2
0
        //public void SendEmailInBackgroundThread(MailMessage mailMessage)
        //{
        //    Thread bgThread = new Thread(new ParameterizedThreadStart(SendEmail));
        //    bgThread.IsBackground = true;
        //    bgThread.Start(mailMessage);
        //}

        public void single_Recipent_Email(string EMAILSETTING_ID, string To, string SUBJECT, string MSG, string CC)
        {
            try
            {
                EmailSend     obemailSetting = new EmailSend();
                emailProperty obEmailprop    = new emailProperty();
                obEmailprop = obemailSetting.Emailsetting(EMAILSETTING_ID);
                //send mail

                SmtpClient client = new SmtpClient(obEmailprop.E_Smtp_Client);
                // bcc = "*****@*****.**";
                client.Port      = obEmailprop.E_Port;
                client.EnableSsl = obEmailprop.E_EnableSsl;
                client.Timeout   = obEmailprop.E_Timeout;

                switch (obEmailprop.E_DeliveryMethod)
                {
                case "SmtpDeliveryMethod.Network":
                    client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    break;

                case "SmtpDeliveryMethod.SpecifiedPickupDirectory":
                    client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    break;

                case "SmtpDeliveryMethod.PickupDirectoryFromIis":
                    client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
                    break;

                default:
                    client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    break;
                }

                client.UseDefaultCredentials = obEmailprop.E_UseDefaultCredentials;
                client.Credentials           = new NetworkCredential(obEmailprop.E_Credentials_UserName, obEmailprop.E_Credentials_Password);
                //smtp.SendCompleted += new SendCompletedEventHandler(smtp_SendCompleted);
                MailMessage msg = new MailMessage();

                msg.To.Add(To);

                if (!string.IsNullOrEmpty(CC) || !string.IsNullOrWhiteSpace(CC))
                {
                    msg.CC.Add(CC);
                }
                //msg.Bcc.Add(BCC);
                msg.From = new MailAddress(obEmailprop.E_Credentials_UserName);

                msg.Subject = SUBJECT;
                msg.Body    = MSG;

                msg.IsBodyHtml = true;
                client.Send(msg);

                switch (obEmailprop.E_Delivery_Notification)
                {
                case "DeliveryNotificationOptions.Delay":
                    msg.DeliveryNotificationOptions = DeliveryNotificationOptions.Delay;
                    break;

                case "DeliveryNotificationOptions.Never":
                    msg.DeliveryNotificationOptions = DeliveryNotificationOptions.Never;
                    break;

                case "DeliveryNotificationOptions.None":
                    msg.DeliveryNotificationOptions = DeliveryNotificationOptions.None;
                    break;

                case "DeliveryNotificationOptions.OnFailure":
                    msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                    break;

                case "DeliveryNotificationOptions.Success":
                    msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
                    break;

                default:
                    msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
                    break;
                }

                //return "SUCCESS";
            }
            catch (Exception ex)
            {
                //{
                //    //lg.WriteLog(ex.Message.ToString(), ex.ToString(), username, Convert.ToString(HttpContext.Current.Request.Url.AbsolutePath), System.Reflection.MethodBase.GetCurrentMethod().Name);
                //    return ex.Message;
            }
        }