Пример #1
0
        public bool sendEmail(HttpContext context, string userEmail, string callBackUrl, IEmailServerModel model, Constant.EmailType emailType, long userId = 0, long systemId = 0)
        {
            if (model.UserName == null)
            {
                model.UserName = context.User.Identity.Name;
            }
            if (userEmail == null)
            {
                userEmail = Convert.ToString(context.Session[Constant.EmailId]);
            }

            //long userId = Convert.ToInt64(context.Session[Constant.UserId]);
            //long sysytemId = (long)context.Session[Constant.SystemId];
            //IEmailLogModel emailLog = generateEmailLogModel(context);

            IEmailLogModel emailLog = new EmailLogModel {
                UserId = userId, SystemId = systemId, To = userEmail
            };

            if (this.SendEmail(emailLog, callBackUrl, model, emailType) == 1)
            {
                return(true);
            }

            return(false);
        }
Пример #2
0
        public Int32 SendEmail(IEmailLogModel emailLog, string callBackUrl, IEmailServerModel model, Constant.EmailType emailType)
        {
            TempUserDAL    _dal          = new TempUserDAL();
            IEmailLogModel emailLogModel = null;
            string         emailBody     = "";
            string         emailSubject  = "";
            int            retVal        = 0;

            retVal = _dal.GetEmailTemplate(model.UserId, model.UserName, callBackUrl, ref emailBody, ref emailSubject, emailType);
            // Initialize emailLogModel
            //emailLogModel = new EmailLogModel() { UserId = model.UserId, To = user.EmailId, Subject = emailSubject, Body = emailBody, EmailType = (int)emailType };
            emailLogModel = new EmailLogModel()
            {
                UserId = emailLog.UserId, To = emailLog.To, Subject = emailSubject, Body = emailBody, EmailType = (int)emailType, SystemId = emailLog.SystemId
            };

            {
                model.SysEmailServers = new List <EmailServerModel>();
                model.SysEmailServers = GetEmailServerList();

                if (model.SysEmailServers.Count > 0)
                {
                    //MailMessage message = new MailMessage();
                    //message.From = new MailAddress("your email address");

                    //message.To.Add(new MailAddress("your recipient"));

                    //message.Subject = "your subject";
                    //message.Body = "content of your email";

                    //SmtpClient client = new SmtpClient();
                    //client.Send(message);



                    Email email = new Email("HireThingsAdminPortal", model.SysEmailServers);
                    email.SetToAddress(emailLog.To);
                    email.SetSubject(emailSubject);
                    email.SetBody(Convert.ToString(emailBody));
                    email.IsBodyHTML = true;
                    if (email.SendEmail())
                    {
                        // Email Log
                        emailLogModel.SentStatus = 1;
                        _dal.EmailLog(emailLogModel);
                        // Email sending successful
                        retVal = 1;
                    }
                    else
                    {
                        // Email Log
                        emailLogModel.SentStatus   = 0;
                        emailLogModel.UnSentReason = "Write Exception Log here";
                        _dal.EmailLog(emailLogModel);
                        retVal = 2;
                    }
                }
                else
                {
                    retVal = 2;
                }
            }

            return(retVal);
        }
Пример #3
0
        public int GetEmailTemplate(long userId, string userName, string callBackUrl, ref string RetEmailTemplate, ref string RetEmailSubject, Constant.EmailType emailType)
        {
            //int retVal = 0;

            Dictionary <string, object> param = new Dictionary <string, object>();

            param.Add(DBObjects.SPParameter.UserId, GetParameter(DBObjects.SPParameter.UserId, ParameterDirection.Input, ((int)SqlDbType.BigInt), 8, userId));
            param.Add(DBObjects.SPParameter.UserName, GetParameter(DBObjects.SPParameter.UserName, ParameterDirection.Input, ((int)SqlDbType.VarChar), 50, userName));
            param.Add(DBObjects.SPParameter.CallBackUrl, GetParameter(DBObjects.SPParameter.CallBackUrl, ParameterDirection.Input, ((int)SqlDbType.VarChar), 1024, PublicFunctions.ConvertNulltoDBNull(callBackUrl)));
            param.Add(DBObjects.SPParameter.RetEmailTemplate, GetParameter(DBObjects.SPParameter.RetEmailTemplate, ParameterDirection.Output, ((int)SqlDbType.VarChar), 3096, RetEmailTemplate));
            param.Add(DBObjects.SPParameter.RetEmailSubject, GetParameter(DBObjects.SPParameter.RetEmailSubject, ParameterDirection.Output, ((int)SqlDbType.VarChar), 500, RetEmailSubject));
            param.Add(DBObjects.SPParameter.RetVal, GetParameter(DBObjects.SPParameter.RetVal, ParameterDirection.Output, ((int)SqlDbType.Int), 4, null));
            param.Add(DBObjects.SPParameter.EmailType, GetParameter(DBObjects.SPParameter.EmailType, ParameterDirection.Input, ((int)SqlDbType.Int), 4, emailType));

            this.ExecuteSP(DBObjects.StoredProcedures.pspEmailTemplate.ToString(), ref param);

            RetEmailTemplate = (string)((SqlParameter)param[DBObjects.SPParameter.RetEmailTemplate]).Value;
            RetEmailSubject  = (string)((SqlParameter)param[DBObjects.SPParameter.RetEmailSubject]).Value;
            return((int)(((SqlParameter)param[DBObjects.SPParameter.RetVal]).Value));
        }