public static EmailMessage BuildMail(MailTypeEnum type, EmailAddress from = null, EmailAddress to = null, string link = "") { var emailMsg = new EmailMessage(); if (from != null) { emailMsg.From.Add(from); } if (to != null) { emailMsg.To.Add(to); } switch (type) { case MailTypeEnum.NewUser: emailMsg.Subject = "New User"; emailMsg.Body = GetTemplate(MailTypeEnum.NewUser.ToString()) ?? ""; //Replace emailMsg.Body = emailMsg.Body.Replace("@name@", to.Name); break; case MailTypeEnum.LoginUser: emailMsg.Subject = "Login User"; emailMsg.Body = GetTemplate(MailTypeEnum.LoginUser.ToString()) ?? ""; //Replace emailMsg.Body = emailMsg.Body.Replace("@name@", to.Name); emailMsg.Body = emailMsg.Body.Replace("@time@", DateTime.Now.ToString()); break; case MailTypeEnum.ConfirmEmail: emailMsg.Subject = "Confirm eamil"; emailMsg.Body = GetTemplate(MailTypeEnum.ConfirmEmail.ToString()) ?? ""; //Replace emailMsg.Body = emailMsg.Body.Replace("@name@", to.Name); emailMsg.Body = emailMsg.Body.Replace("@link@", link); break; case MailTypeEnum.ForgetPassword: emailMsg.Subject = "Forget Password"; emailMsg.Body = GetTemplate(MailTypeEnum.ForgetPassword.ToString()) ?? ""; //Replace emailMsg.Body = emailMsg.Body.Replace("@name@", to.Name); emailMsg.Body = emailMsg.Body.Replace("@link@", link); break; default: break; } return(emailMsg); }
protected void LoginButton_Click(object sender, EventArgs e) { MailTypeEnum mType = SelectedMailType; string serverURL = ServerURLTextBox.Text.Trim(); string domain = DomainTextBox.Text.Trim(); string username = UsernameTextBox.Text.Trim(); string password = PasswordTextBox.Text.Trim(); bool sslEnabled = SSLEnabledCheckBox.Checked; int sslPort = Convert.ToInt32(SSLPortTextBox.Text.Trim()); MailHelper mailHelper = null; switch (mType) { case MailTypeEnum.ExchangeServer: mailHelper = new ExchangeHelper(serverURL, domain, username, password, mType); break; case MailTypeEnum.IMAP: mailHelper = new IMAPHelper(serverURL, username, password, sslEnabled, sslPort, mType); break; case MailTypeEnum.POP3: mailHelper = new POP3Helper(serverURL, username, password, sslEnabled, sslPort, mType); break; default: return; } if (mailHelper.VerfiyCredentials()) { Session[Constants.MailHelperSession] = mailHelper; Response.Redirect("~/MailBox.aspx"); } else { ConnectionError.Visible = true; } }
public POP3Helper(string su, string u, string p, bool ssl, int port, MailTypeEnum mte) { ServerURL = su; Username = u; Password = p; SSLEnabled = ssl; SSLPort = port; MailType = mte; }
public ExchangeHelper(string su, string dom, string u, string p, MailTypeEnum mte) { ServerURL = su; Domain = dom; Username = u; Password = p; MailType = mte; }
/// <summary> /// This method returns all created mail of the given type. /// </summary> /// <param name="mailType">This is the type of the mail.</param> /// <returns>Mail List.</returns> public static List <Mail> GetAll(MailTypeEnum mailType) { return(InMemoryDatabaseSingleton.DatabaseInstance.SelectMany <Mail>( x => x.MailType == mailType).OrderByDescending( x => x.CreationDate).ToList()); }
/// <summary> /// This method gets the mail based on the type. /// </summary> /// <param name="mailTypeEnum">This is the type of the mail.</param> /// <returns>The mail details.</returns> public static Mail Get(MailTypeEnum mailTypeEnum) { return(InMemoryDatabaseSingleton.DatabaseInstance.SelectMany <Mail>( x => x.MailType == mailTypeEnum && x.IsCreated).OrderByDescending( x => x.CreationDate).First()); }