/// <summary> /// Sends the username associated with the email address listed to the email address. /// </summary> /// <param name="email">The email address of the user.</param> /// <param name="role">The role: DJ or Mobile</param> /// <returns>The outcome of the operation.</returns> public Response SendEmailWithUsername(string email) { Response r; using (DatabaseConnectivity db = new DatabaseConnectivity()) { // Try to establish a database connection r = db.OpenConnection(); if (r.error) return r; List<string> DJUsernames; List<string> mobileUsernames; r = db.DJGetUsernamesByEmail(email, out DJUsernames); if (r.error) return r; r = db.MobileGetUsernamesByEmail(email, out mobileUsernames); if (r.error) return r; List<string> usernames = new List<string>(); List<string> roles = new List<string>(); foreach (string djUsername in DJUsernames) { usernames.Add(djUsername); roles.Add("DJ"); } foreach (string mobileUsername in mobileUsernames) { usernames.Add(mobileUsername); roles.Add("Singer"); } try { MailMessage mail = GenerateUsernameEmail(email, usernames, roles); SmtpClient mailServer = new SmtpClient("smtp.live.com"); mailServer.Port = 25; mailServer.UseDefaultCredentials = false; mailServer.Credentials = new System.Net.NetworkCredential(mobiokeUsername, mobiokePassword); mailServer.EnableSsl = true; mailServer.Send(mail); return r; } catch (Exception e) { r.error = true; r.message = "Exception in SendEmailWithUsername: " + e.Message; return r; } } }
/// <summary> /// Sends the username associated with the email address listed to the email address. /// </summary> /// <param name="email">The email address of the user.</param> /// <param name="role">The role: DJ or Mobile</param> /// <returns>The outcome of the operation.</returns> public Response SendEmailWithUsername(string email) { ExpResponse r = new ExpResponse(); using (DatabaseConnectivity db = new DatabaseConnectivity()) { // Try to establish a database connection r = db.OpenConnection(); if (r.error) return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web); List<string> DJUsernames; List<string> mobileUsernames; r = db.DJGetUsernamesByEmail(email, out DJUsernames); if (r.error) return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web); r = db.MobileGetUsernamesByEmail(email, out mobileUsernames); if (r.error) return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Web); if (DJUsernames.Count == 0 && mobileUsernames.Count == 0) { r.setErMsg(true, Messages.MSG_EMAIL_NOT_FOUND); return r; } List<string> usernames = new List<string>(); List<string> roles = new List<string>(); foreach (string djUsername in DJUsernames) { usernames.Add(djUsername); roles.Add("DJ"); } foreach (string mobileUsername in mobileUsernames) { usernames.Add(mobileUsername); roles.Add("Singer"); } try { MailMessage mail = GenerateUsernameEmail(email, usernames, roles); SmtpClient mailServer = new SmtpClient("smtp.live.com"); mailServer.Port = 25; mailServer.UseDefaultCredentials = false; mailServer.Credentials = new System.Net.NetworkCredential(Settings.EMAIL_ADR, Settings.EMAIL_PSWD); mailServer.EnableSsl = true; mailServer.Send(mail); return r; } catch (Exception e) { r.setErMsgStk(true, e.Message, e.StackTrace); return Common.LogErrorRetNewMsg(r, Messages.ERR_EMAIL_SERVER, Common.LogFile.Web); } } }