public static async Task<bool> SendMailFriendRequest(FriendRequestEmail data) { try { var client = new SmtpClient(); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = true; var supportEmail = ConfigurationManager.AppSettings["CUSTOMER_SUPPORT_EMAIL_SENDER"]; var displayName = ConfigurationManager.AppSettings["CUSTOMER_SUPPORT_EMAIL_NAME"]; //var email_temp = ConfigurationManager.AppSettings["CUSTOMER_SUPPORT_EMAIL_SENDER_TEST"]; var from = new MailAddress(supportEmail, displayName); var to = new MailAddress(data.to_email); var mailMessage = new MailMessage(from, to) { Subject = "You have a friend request!", Body = GetEmailBody(ConfigurationManager.AppSettings["FriendRequestTemplate"], data), IsBodyHtml = true }; await client.SendMailAsync(mailMessage); return true; } catch { return false; } }
public async Task<ActionResult> AddFriend(string friend) { var param = HttpContext.Request.Params; var friendName = string.IsNullOrEmpty(friend) ? string.Empty : friend.ToLower().Trim('"'); var api = GoPlayApi.Instance; var userFriend = api.GetUserByUserName(friend).Data; if (userFriend == null) return Json(new { success = false }); //TODO: add friend to chat system of SignalR later,need to apply new code 3/9 string gtokenSession = HttpContext.Session["gtoken_section"] == null ? string.Empty : HttpContext.Session["gtoken_section"].ToString(); bool isSendRequest = api.SendRequest(gtokenSession, CurrentUser.Id, userFriend.id, null); if (isSendRequest) { string rootUrl = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, String.Empty); var template = new FriendRequestEmail { receiver_display_name = userFriend.GetDisplayName(), to_email = userFriend.email, sender_display_name = CurrentUser.GetDisplayName(), sender_avatar = CurrentUser.avatar_filename, sender_username = CurrentUser.UserName }; await EmailHelper.SendMailFriendRequest(template); } return Json(new { success = string.IsNullOrEmpty(gtokenSession) ? false : isSendRequest }); }