private static void SendMail(string subject, string body, string emailTo) { // For testing only, never include password in source code. var mailServiceHelper = new MailServiceHelper("*****@*****.**", "password", "smtp.abcmail.com", 465, true); mailServiceHelper.SendEmail(subject, body, emailTo, "TestMailKit"); }
protected void Page_Load(object sender, EventArgs e) { AjaxPro.Utility.RegisterTypeForAjax(GetType(), Page); Page.RegisterBodyScripts("~/usercontrols/management/MailService/js/mailservice.js"); Page.ClientScript.RegisterClientScriptBlock(GetType(), "mailservice_style", "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + WebPath.GetPath("usercontrols/management/mailservice/css/mailservice.css") + "\">", false); var mailServerInfo = MailServiceHelper.GetMailServerInfo(); if (mailServerInfo == null) { ServerIp = string.Empty; User = DefaultUser; Password = DefaultPassword; } else { ServerIp = mailServerInfo.Api.Server; var connectionParts = mailServerInfo.DbConnection.Split(';'); foreach (var connectionPart in connectionParts) { if (connectionPart.StartsWith("User ID=")) { User = connectionPart.Replace("User ID=", ""); } if (connectionPart.StartsWith("Password="******"Password="******""); } } } }
public object Connect(string ip, string user, string password) { try { IPAddress ipAddress; if (string.IsNullOrEmpty(ip) || !IPAddress.TryParse(ip, out ipAddress)) { throw new ArgumentException("ip"); } if (!PingHost(ip, 3306)) { throw new Exception(string.Format(Resources.Resource.MailServicePingErrorMsg, ip)); } if (string.IsNullOrEmpty(user)) { throw new ArgumentException("user"); } if (string.IsNullOrEmpty(password)) { throw new ArgumentException("password"); } var connectionString = string.Format(ConnectionStringFormat, ip, DefaultDatabase, user, password); var data = MailServiceHelper.GetDataFromExternalDatabase(MailServiceDbId, connectionString, ip); if (data == null || data.Length < 2 || string.IsNullOrEmpty(data[0]) || string.IsNullOrEmpty(data[1])) { throw new Exception(Resources.Resource.MailServiceCouldNotGetErrorMsg); } return(new { Status = "success", Message = Resources.Resource.MailServiceConnectSuccessMsg, Ip = ip, User = user, Password = password, Token = data[0], Host = data[1] }); } catch (Exception exception) { LogManager.GetLogger("ASC.Web.MailService").Error(exception); return(new { Status = "error", Message = exception.Message.HtmlEncode() }); } }
private static string[] GetAuthData(string connectionString, string ip) { var data = MailServiceHelper.GetDataFromExternalDatabase(MailServiceHelper.MailServiceDbId, connectionString, ip); if (data == null || data.Length < 2 || string.IsNullOrEmpty(data[0]) || string.IsNullOrEmpty(data[1])) { throw new Exception(Resource.MailServiceCouldNotGetErrorMsg); } return(data); }
private static string GetHostname(string connectionString, string ip) { var hostname = MailServiceHelper.GetHostnameFromExternalDatabase(MailServiceHelper.MailServiceDbId, connectionString, ip); if (string.IsNullOrEmpty(hostname)) { throw new Exception(Resource.MailServiceCouldNotGetHostnameErrorMsg); } return(hostname); }
private static string GetToken(string connectionString) { var token = MailServiceHelper.GetTokenFromExternalDatabase(MailServiceHelper.MailServiceDbId, connectionString); if (string.IsNullOrEmpty(token)) { throw new Exception(Resource.MailServiceCouldNotGetTokenErrorMsg); } return(token); }
protected void Page_Load(object sender, EventArgs e) { AjaxPro.Utility.RegisterTypeForAjax(GetType(), Page); Page.RegisterBodyScripts("~/UserControls/Management/MailService/js/mailservice.js"); Page.ClientScript.RegisterClientScriptBlock(GetType(), "mailservice_style", "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + WebPath.GetPath("UserControls/Management/MailService/css/mailservice.css") + "\">", false); var mailServerInfo = CoreContext.Configuration.Standalone ? MailServiceHelper.GetMailServerInfo() : null; if (mailServerInfo == null) { SqlHost = string.Empty; ApiHost = string.Empty; Database = MailServiceHelper.DefaultDatabase; User = MailServiceHelper.DefaultUser; Password = MailServiceHelper.DefaultPassword; } else { ApiHost = mailServerInfo.Api.Server; var connectionParts = mailServerInfo.DbConnection.Split(';'); foreach (var connectionPart in connectionParts) { if (connectionPart.StartsWith("Server=")) { SqlHost = connectionPart.Replace("Server=", ""); } if (connectionPart.StartsWith("Database=")) { Database = connectionPart.Replace("Database=", ""); } if (connectionPart.StartsWith("User ID=")) { User = connectionPart.Replace("User ID=", ""); } if (connectionPart.StartsWith("Password="******"Password="******""); } } } HelpLink = CommonLinkUtility.GetHelpLink(); }
protected string GetProductLabel(IWebItem product) { if (product.ID == WebItemManager.CRMProductID) { return(Resource.ProductCRMAndVoIP); } if (product.ID == WebItemManager.MailProductID && SetupInfo.IsVisibleSettings("AdministrationPage") && CurrentUser.IsAdmin() && (!CoreContext.Configuration.Standalone || MailServiceHelper.IsMailServerAvailable())) { return(Resource.AdministrationLabel); } return(HttpUtility.HtmlEncode(product.Name)); }
private static void Save(string connectionString, string ip, string token, string host) { var mailServer = new MailServerInfo { DbConnection = connectionString, Api = new MailServerApiInfo { Port = MailServiceHelper.DefaultPort, Protocol = MailServiceHelper.DefaultProtocol, Server = ip, Token = token, Version = MailServiceHelper.DefaultVersion } }; MailServiceHelper.UpdateDataFromInternalDatabase(host, mailServer); MessageService.Send(HttpContext.Current.Request, MessageAction.MailServiceSettingsUpdated); }
public object GetMailServerInfo() { return(MailServiceHelper.GetMailServerInfo()); }
public static bool IsAdministrationPageAvailable() { return(SetupInfo.IsVisibleSettings <AdministrationPage>() && (!CoreContext.Configuration.Standalone || MailServiceHelper.IsMailServerAvailable())); }
public object Save(string ip, string user, string password, string token, string host) { try { IPAddress ipAddress; if (string.IsNullOrEmpty(ip) || !IPAddress.TryParse(ip, out ipAddress)) { throw new ArgumentException("ip"); } if (string.IsNullOrEmpty(user)) { throw new ArgumentException("user"); } if (string.IsNullOrEmpty(password)) { throw new ArgumentException("password"); } if (string.IsNullOrEmpty(token)) { throw new ArgumentException("token"); } if (string.IsNullOrEmpty(host)) { throw new ArgumentException("host"); } var connectionString = string.Format(ConnectionStringFormat, ip, DefaultDatabase, user, password); var mailServer = new MailServerInfo { DbConnection = connectionString, Api = new MailServerApiInfo { Port = DefaultPort, Protocol = DefaultProtocol, Server = ip, Token = token, Version = DefaultVersion } }; MailServiceHelper.UpdateDataFromInternalDatabase(host, mailServer); ClearCache(); return(new { Status = "success", Message = Resources.Resource.MailServiceSaveSuccessMsg }); } catch (Exception exception) { LogManager.GetLogger("ASC.Web.MailService").Error(exception); return(new { Status = "error", Message = exception.Message.HtmlEncode() }); } }