/// <summary> /// Sends an email notification /// with the card number to a single user. /// </summary> /// <param name="smtpHostname"></param> /// <param name="targetUsername"></param> /// <param name="senderAddress"></param> /// <param name="targetIdField"></param> public void SendSingleEmail(string smtpHostname, string targetUsername, string senderAddress, int targetIdField) { string resolvedIdField = PaperCutProxyWrapper.ResolveCardField(targetIdField); string targetEmail = _serverProxy.GetUserProperty(targetUsername, Common.Constants.PaperCut.Properties.Email); string retrievedId = _serverProxy.GetUserProperty(targetUsername, resolvedIdField); try { SmtpClient smtpClient = new SmtpClient(); smtpClient.Host = smtpHostname; smtpClient.Port = 25; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.UseDefaultCredentials = false; SendEmail(smtpClient, senderAddress, targetEmail, retrievedId); } catch (Exception) { Console.WriteLine(Common.Constants.Smtp.Email.UnableToSend); } }
/// <summary> /// Sends an email notification /// with the card number to all users. /// </summary> /// <param name="smtpHostname"></param> /// <param name="senderAddress"></param> /// <param name="targetIdField"></param> public void SendEmailsToAllUsers(string smtpHostname, string senderAddress, int targetIdField) { try { if (!string.IsNullOrEmpty(smtpHostname) && !string.IsNullOrEmpty(senderAddress)) { string resolvedIdField = PaperCutProxyWrapper.ResolveCardField(targetIdField); string[] usernames = PaperCutProxyWrapper.GetUserAccounts(_serverProxy); List <string> emails = null; List <string> idNumbers = null; for (int i = 0; i < usernames.Length; i++) { string[] retrievedProperties = _serverProxy.GetUserProperties(usernames[i], new string[] { Common.Constants.PaperCut.Properties.Email, resolvedIdField }); emails.Add(retrievedProperties[0]); idNumbers.Add(retrievedProperties[1]); } SmtpClient smtpClient = new SmtpClient(); smtpClient.Host = smtpHostname; smtpClient.Port = 25; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.UseDefaultCredentials = false; for (int i = 0; i < usernames.Length; i++) { SendEmail(smtpClient, senderAddress, emails[i], idNumbers[i]); } } } catch { Console.WriteLine(Common.Constants.Smtp.Email.UnableToSend); } }