public bool sendFCMNotification(string token, string title, string message) { bool IsSendToFcm = false; try { #region Send Spectro Data To FCM FCMNotification.FCMResponseObject FCM_Response = new FCMNotification.FCMResponseObject(); FCMNotification notification = new FCMNotification(); if (!String.IsNullOrEmpty(token)) { string response = notification.PushNotifyAsync(token, title, message); FCM_Response = Newtonsoft.Json.JsonConvert.DeserializeObject <FCMNotification.FCMResponseObject>(response); if (FCM_Response.success > 0 && FCM_Response.failure == 0) { IsSendToFcm = true; } else { IsSendToFcm = false; } } #endregion } catch (Exception ex) { } return(IsSendToFcm); }
public static Bundle ToBundle(this FCMNotification notification) { var bundle = new Bundle(); bundle.PutString(BundleKeyBody, notification.Body); bundle.PutString(BundleKeyTitle, notification.Title); bundle.PutString(BundleKeyImageUrl, notification.ImageUrl); bundle.PutBundle(BundleKeyData, notification.Data?.ToBundle()); return(bundle); }
// Build notification public async Task <bool> HandleNotification() { IsItMyTurnContext context = new IsItMyTurnContext(); string nextApartmentInShift = GetApartmentForNextShift(); // Title and body for notification FCMNotification notification = new FCMNotification(); notification.title = "Leikkuuvuoro vaihtui!"; notification.body = "Seuraavana vuorossa: " + nextApartmentInShift; notification.sound = "default"; // Tokens to array from database which will get the notification string[] fcmTokens = (from ft in context.FcmTokens select ft.Token).ToArray(); List <bool> successList = new List <bool>(); // The notification is sent to device and the result will be added to list of successes foreach (var token in fcmTokens) { FCMBody body = new FCMBody(); body.registration_ids = new string[] { token }; body.notification = notification; bool result = await SendNotification(body); successList.Add(result); } // If all the notification send responses are OK, return true bool allTrue = successList.All(s => Equals(true, s)); if (allTrue) { return(true); } else { return(false); } }
public static bool sendFCMNotification(string token, string title, string message) { bool IsSendToFcm = false; try { #region Send Spectro Data To FCM FCMNotification.FCMResponseObject FCM_Response = new FCMNotification.FCMResponseObject(); FCMNotification notification = new FCMNotification(); if (!String.IsNullOrEmpty(token)) { string response = notification.PushNotifyAsync(token, title, message); FCM_Response = Newtonsoft.Json.JsonConvert.DeserializeObject <FCMNotification.FCMResponseObject>(response); if (FCM_Response.success > 0 && FCM_Response.failure == 0) { IsSendToFcm = true; } else { IsSendToFcm = false; } } #endregion } catch (Exception ex) { //IsSendToFcm = false; //Console.WriteLine(ex.Message); //using (System.IO.StreamWriter file = new System.IO.StreamWriter(GetDirectory + "\\ErrorLog.txt", true)) //{ // file.WriteLine("Date >> " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss tt") + " >> ERROR >> " + ex.Message.ToString()); //} } return(IsSendToFcm); }
public static bool SendPushNotification(string device_token, string body_data, Guid guid, int devicetype) { bool IsSendToFcm = false; try { FCMNotification fcmpush = new FCMNotification(); FCMResponse s = fcmpush.PushNotifyAsync(device_token, body_data, guid, devicetype); if (s.success > 0) { IsSendToFcm = true; } else { IsSendToFcm = false; } } catch (Exception ex) { throw ex; } return(IsSendToFcm); }
public static FCMNotification ToFCMNotification(this NSDictionary userInfo) { if (userInfo["aps"] is NSDictionary apsDict) { var alert = apsDict["alert"]; if (alert is NSDictionary dict) { return(new FCMNotification(GetBody(dict), GetTitle(dict), GetImageUrl(userInfo), userInfo.ToDictionary())); } else if (alert != null) { return(new FCMNotification(alert.ToString(), "", "", userInfo.ToDictionary())); } } else { var notification = userInfo["notification"]; if (notification is NSDictionary dict) { return(new FCMNotification(GetBody(dict), GetTitle(dict), GetImageUrl(dict), userInfo.ToDictionary())); } } return(FCMNotification.Empty()); }
private void SendMail(string CommenterName, string BlogersMail, string BlogersName, string BlogersDesc) { try { DataTable dtRecord = new DataTable(); string body = null; string MailURL = ConfigurationManager.AppSettings["MailURL"]; string MailTo = BlogersMail; string MailURLFinal = MailURL + "/BlogsComments.aspx?intBlogId=" + Convert.ToString(ViewState["intBlogId"]); dtRecord.Clear(); objdoreg.UserName = MailTo; dtRecord = objdareg.GetDataTableRecord(objdoreg, DA_Registrationdetails.RegistrationDetails.UserRecordByMail); using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate.htm"))) { body = reader.ReadToEnd(); } body = body.Replace("{UserName}", BlogersName); body = body.Replace("{Content}", "<span style='font-weight:bold;font-size:14px;color:#373A36;'>" + CommenterName + "</span> has commented on your blog titled " + "<span style='font-weight:bold;font-size:14px;color:#373A36;'>" + BlogersDesc + "</span>" + "<br><br><a href='" + MailURLFinal + "' style ='background: #01B7BD;padding: 5px 10px; border-radius: 15px;color: #fff;text-decoration: none;'>View Comment</a>"); string subject = CommenterName + " has commented on your blog"; EmailSender.SendEmail(MailTo, subject, body); FCMNotification.Send(CommenterName + " has commented on your blog", CommenterName + " has commented on your blog titled " + BlogersDesc, Convert.ToString(dtRecord.Rows[0]["intRegistrationId"]), MailURLFinal); } catch (Exception ex) { ex.Message.ToString(); } }
public FCMNotificationTappedEventArgs(FCMNotification notification) { Notification = notification; }
private void SendGroupMail(string mailid, string name) { try { DataTable dtRecord = new DataTable(); string body = null; SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); string mailfrom = ConfigurationManager.AppSettings["mailfrom"]; string mailServer = ConfigurationManager.AppSettings["mailServer"]; string username = ConfigurationManager.AppSettings["UserName"]; string Password = ConfigurationManager.AppSettings["Password"]; string Port = ConfigurationManager.AppSettings["Port"]; string MailURL = ConfigurationManager.AppSettings["MailURL"]; string MailSSL = ConfigurationManager.AppSettings["MailSSL"]; string DisplayName = ConfigurationManager.AppSettings["DisplayName"]; string MailTo = mailid; string Mailbody = ""; dtRecord.Clear(); objdoreg.UserName = mailid; dtRecord = objdareg.GetDataTableRecord(objdoreg, DA_Registrationdetails.RegistrationDetails.UserRecordByMail); NetworkCredential cre = new NetworkCredential(username, Password); DataSet ds1 = new DataSet(); ds1 = (DataSet)ViewState["GetGroupDetailsByGroupId"]; SmtpClient clientip = new SmtpClient(mailServer); clientip.Port = Convert.ToInt32(Port); clientip.UseDefaultCredentials = true; clientip.Credentials = cre; if (MailSSL != "0") { clientip.EnableSsl = true; } string MailUrlFinal = MailURL + "/groups-members.aspx?GrpId=" + ds1.Tables[0].Rows[0]["inGroupId"]; try { MailMessage Rmm2 = new MailMessage(); Rmm2.IsBodyHtml = true; Rmm2.From = new System.Net.Mail.MailAddress(mailfrom, DisplayName); Rmm2.Body = Mailbody.ToString(); System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(""); if (Convert.ToString(ds1.Tables[0].Rows[0]["strAccess"]) == "A") { //htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<b>Skorkel group joining</b>" // + "<br><br>" + "Dear " + name + "<br><br> " // + "Your " + Convert.ToString(ds1.Tables[0].Rows[0]["strGroupName"]) + " group has been joined by " + Session["LoginName"] + "<br><br>" + "Regards," + "<br>" // + "Skorkel Team" + "<br><br>****This is a system generated Email. Kindly do not reply****", null, "text/html"); using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate.htm"))) { body = reader.ReadToEnd(); } body = body.Replace("{UserName}", name); //body = body.Replace("{Content}", ViewState["LoginName"] + // " added you to the " + Convert.ToString(ds1.Tables[0].Rows[0]["strGroupName"]) + " group. <br>"); body = body.Replace("{Content}", "Your <b>" + Convert.ToString(ds1.Tables[0].Rows[0]["strGroupName"]) + "</b> group has been joined by <b>" + Session["LoginName"] + "</b>.<br>" + "Please click below to view group details: " + "<br><br><a href = '" + MailUrlFinal + "' style='background:#01B7BD;padding:5px 10px;border-radius:15px;color:#fff;text-decoration: none;'>View Details</a>"); body = body.Replace("{RedirectURL}", MailURL); htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html); Rmm2.To.Clear(); Rmm2.To.Add(MailTo); //Rmm2.Subject = "Skorkel group joining."; Rmm2.Subject = "Skorkel group joining " + Convert.ToString(ds1.Tables[0].Rows[0]["strGroupName"]) + " - " + Session["LoginName"]; FCMNotification.Send("Skorkel group joining " + Convert.ToString(ds1.Tables[0].Rows[0]["strGroupName"]) + " - " + Session["LoginName"], "Your " + Convert.ToString(ds1.Tables[0].Rows[0]["strGroupName"]) + " group has been joined by " + Session["LoginName"] + ".", Convert.ToString(dtRecord.Rows[0]["intRegistrationId"]), MailUrlFinal); } else if (Convert.ToString(ds1.Tables[0].Rows[0]["strAccess"]) == "R") { using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate.htm"))) { body = reader.ReadToEnd(); } body = body.Replace("{UserName}", name); body = body.Replace("{Content} ", "<span style='font-weight:bold;font-size:14px;color:#373A36;'>" + Session["LoginName"] + "</span> wants to join <span style='font-weight:bold;font-size:14px;color:#373A36;'>" + Convert.ToString(ds1.Tables[0].Rows[0]["strGroupName"]) + "</span>" + "<br><br><a href='" + MailUrlFinal + "' style ='background: #01B7BD;padding: 5px 10px; border-radius: 15px;color: #fff;text-decoration: none;'>Accept</a>"); body = body.Replace("{RedirectURL}", MailURL); htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html); //htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<b>Skorkel group joining invitation</b>" + "<br><br>" + " " + name + " " + "You have a Skorkel group joining request posted by " + Session["LoginName"] + "<br><br><br>" + "Thanks," + "<br>" + "The Skorkel Team", null, "text/html"); Convert.ToString(ds1.Tables[0].Rows[0]["strGroupName"]); //htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<b>Skorkel Group Joining Request</b>" + "<br><br>" + "Dear " // + name + " <br><br>" // + Session["LoginName"] + " request you to allow joining " // + Convert.ToString(ds1.Tables[0].Rows[0]["strGroupName"]) + " group.<br><br>" // + "Regards," + "<br>" + "Skorkel Team" // + "<br><br>****This is a system generated Email. Kindly do not reply****", null, "text/html"); //Member_Name request you to allow joining 'Group_name' group Rmm2.To.Clear(); Rmm2.To.Add(MailTo); //Rmm2.Subject = "Skorkel Group Joining Request."; Rmm2.Subject = "Request to Join " + Convert.ToString(ds1.Tables[0].Rows[0]["strGroupName"]) + " - " + Session["LoginName"]; FCMNotification.Send("Request to Join " + Convert.ToString(ds1.Tables[0].Rows[0]["strGroupName"]) + " - " + Session["LoginName"], Session["LoginName"] + " wants to join " + Convert.ToString(ds1.Tables[0].Rows[0]["strGroupName"]), Convert.ToString(dtRecord.Rows[0]["intRegistrationId"]), MailUrlFinal); } else if (RequestType == "Send UnJoin request") { htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<b>Skorkel group unjoining invitation</b>" + "<br><br>" + " " + name + " " + "Your group has been unjoined by " + Session["LoginName"] + "<br><br><br>" + "Thanks," + "<br>" + "The Skorkel Team", null, "text/html"); Rmm2.To.Clear(); Rmm2.To.Add(MailTo); Rmm2.Subject = "Skorkel group unjoining notification"; } Rmm2.AlternateViews.Add(htmlView); Rmm2.IsBodyHtml = true; clientip.Send(Rmm2); Rmm2.To.Clear(); } catch (FormatException ex) { ex.Message.ToString(); return; } catch (SmtpException ex) { ex.Message.ToString(); return; } finally { conn.Close(); } } catch (Exception ex) { ex.Message.ToString(); } }
/// <summary> /// Send FCM Message /// </summary> /// <param name="message"></param> private void SendFCM(IPDMessage message) { FCMNotification.Notify(message.ReceiverUri, message.SenderUri, message.Subject, commParams.FCMAppID, commParams.FCMSenderID); }
private void SendMail(string status, string TableName) { try { DataTable dtRecord = new DataTable(); DataTable dtGrpRecord = new DataTable(); string body = null; string Name = null; SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); string mailfrom = ConfigurationManager.AppSettings["mailfrom"]; string mailServer = ConfigurationManager.AppSettings["mailServer"]; string username = ConfigurationManager.AppSettings["UserName"]; string Password = ConfigurationManager.AppSettings["Password"]; string Port = ConfigurationManager.AppSettings["Port"]; string MailURL = ConfigurationManager.AppSettings["MailURL"]; string MailSSL = ConfigurationManager.AppSettings["MailSSL"]; string MailTo = ""; if (TableName == "Ask For Recommendation" && status == "Confirm") { MailTo = Convert.ToString(ViewState["AskForRecommMailId"]); } else { MailTo = hdnEmailId.Value; } string Mailbody = ""; dtRecord.Clear(); objdoreg.UserName = MailTo; dtRecord = objdareg.GetDataTableRecord(objdoreg, DA_Registrationdetails.RegistrationDetails.UserRecordByMail); Name = Convert.ToString(dtRecord.Rows[0]["vchrFirstName"] + " " + dtRecord.Rows[0]["vchrLastName"]); //objGrpJoinDA.AddEditDel_Scrl_UserGroupJoin(objGrpJoinDO, DA_Scrl_UserGroupJoin.Scrl_UserGroupJoin.Update); dtGrpRecord = objGrpJoinDA.GetDataTable(objGrpJoinDO, DA_Scrl_UserGroupJoin.Scrl_UserGroupJoin.GetSingleGroupRecord); //NetworkCredential cre = new NetworkCredential(username, Password); SmtpClient clientip = new SmtpClient(mailServer); clientip.Port = Convert.ToInt32(Port); //clientip.UseDefaultCredentials = true; //clientip.Credentials = cre; //if (MailSSL != "0") // clientip.EnableSsl = true; clientip.UseDefaultCredentials = false; if (MailSSL != "0") { clientip.EnableSsl = true; } clientip.Credentials = new System.Net.NetworkCredential(username, Password); string DisplayName = ConfigurationManager.AppSettings["DisplayName"]; try { MailMessage Rmm2 = new MailMessage(); Rmm2.IsBodyHtml = true; Rmm2.From = new System.Net.Mail.MailAddress(mailfrom, DisplayName); Rmm2.Body = Mailbody.ToString(); System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(""); if (TableName == "Scrl_UserRequestInvitationTbl") { if (status == "Confirm") { using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate.htm"))) { body = reader.ReadToEnd(); } body = body.Replace("{UserName}", Name); body = body.Replace("{Content}", "Your friend request has been accepted by <span style='font-weight:bold;font-size:14px;color:#373A36;'>" + Session["LoginName"] + "</span>" + "<br><br><br>"); body = body.Replace("{RedirectURL}", MailURL); htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html); //htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<b>Skorkel Request Invitation Status</b>" // + "<br><br>" + " " // + "Your Request Invitation has been accepted by " + Session["LoginName"] + ".<br><br><br>" // + "Regards," + "<br>" + "Skorkel Team" // + "<br><br>****This is a system generated Email. Kindly do not reply****", null, "text/html"); } else if (status == "Delete") { return; } //Rmm2.Subject = "Skorkel Request Invitation Status."; string MailUrlFinal = MailURL + "/Profile2.aspx?RegId=" + Convert.ToString(ViewState["UserID"]); Rmm2.Subject = "Friend Request Accepted - " + Session["LoginName"]; FCMNotification.Send("Friend Request Accepted - " + Session["LoginName"], "Your friend request has been accepted by " + Session["LoginName"], Convert.ToString(dtRecord.Rows[0]["intRegistrationId"]), MailUrlFinal); } else if (TableName == "Scrl_UserRecommendationTbl") { if (status == "Confirm") { htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<b>Skorkel Recommendation Status</b>" + "<br><br>" + " " + "Your request for recommendation has been accepted by " + Session["LoginName"] + "<br><br><br>" + "Thanks," + "<br>" + "The Skorkel Team", null, "text/html"); } else if (status == "Delete") { htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<b>Skorkel Recommendation Status</b>" + "<br><br>" + " " + "Your request for recommendation has not been accepted by " + Session["LoginName"] + "<br><br><br>" + "Thanks," + "<br>" + "The Skorkel Team", null, "text/html"); } Rmm2.Subject = "Skorkel Recommendation Status"; } else if (TableName == "Scrl_UserGroupJoiningTbl") { string MailUrlFinal = MailURL + "/Group-Profile.aspx?GrpId=" + ViewState["lblGroupName"]; if (status == "Confirm") { //htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<b>Skorkel Group Joining Status</b>" // + "<br><br>" + " " + "Your request to join " + ViewState["lblGroupName"] + " group has been accepted by " // + Session["LoginName"] + "<br><br><br>" + "Thanks," // + "<br>" + "Skorkel Team" // + "<br><br>****This is a system generated Email. Kindly do not reply**** ", null, "text/html"); using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate.htm"))) { body = reader.ReadToEnd(); } body = body.Replace("{UserName}", Name); body = body.Replace("{Content}", "You are a now a member of " + "<span style='font-weight:bold;font-size:14px;color:#373A36;'> " + ViewState["lblGroupName"] + "</span>." + "<br><br><a href='" + MailUrlFinal + "' style ='background: #01B7BD;padding: 5px 10px; border-radius: 15px;color: #fff;text-decoration: none;'>View Group</a>"); body = body.Replace("{RedirectURL}", MailURL); htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html); } else if (status == "Delete") { return; } Rmm2.Subject = "Request to Join " + ViewState["lblGroupName"] + " Accepted"; FCMNotification.Send("Request to Join " + ViewState["lblGroupName"] + " Accepted", "You are a now a member of " + ViewState["lblGroupName"] + ".", Convert.ToString(dtRecord.Rows[0]["intRegistrationId"]), MailUrlFinal); } else if (TableName == "Scrl_UserRecommendationChildTbl") { if (status == "Confirm") { htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<b>Skorkel Asked Recommendation Status</b>" + "<br><br>" + " " + "Your request for recommendation has been accepted by " + Session["LoginName"] + "<br><br><br>" + "Thanks," + "<br>" + "The Skorkel Team", null, "text/html"); } else if (status == "Delete") { htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<b>Skorkel Asked Recommendation Status</b>" + "<br><br>" + " " + "Your request for recommendation has not been accepted by " + Session["LoginName"] + "<br><br><br>" + "Thanks," + "<br>" + "The Skorkel Team", null, "text/html"); } Rmm2.Subject = "Skorkel Asked Recommendation Status"; } else if (TableName == "Ask For Recommendation") { if (status == "Confirm") { htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<b>Skorkel Ask For Recommendation Status</b>" + "<br><br>" + " " + Convert.ToString(ViewState["AskForRecommName"]) + " " + "This is a replay for your asked recommendation request,which is accepted by " + Session["LoginName"] + "<br><br><br>" + "Thanks," + "<br>" + "The Skorkel Team", null, "text/html"); } else if (status == "Delete") { htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<b>Skorkel Ask Recommendation Status</b>" + "<br><br>" + " " + "Your request for recommendation has not been accepted by " + Session["LoginName"] + "<br><br><br>" + "Thanks," + "<br>" + "The Skorkel Team", null, "text/html"); } Rmm2.Subject = "Skorkel Asked Recommendation "; } else if (TableName == "Scrl_RequestGroupJoin") { if (status == "Confirm") { htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<b>Skorkel Group Invitation Status</b>" + "<br><br>Your invitation of " + ViewState["lblGroupName"] + " group joining has been accepted by " + Session["LoginName"] + "<br><br>" + "Regards," + "<br>" + "Skorkel Team" + "<br><br>****This is a system generated Email. Kindly do not reply**** ", null, "text/html"); } else if (status == "Delete") { return; } Rmm2.Subject = "Skorkel Group Invitation Status. "; } Rmm2.To.Clear(); Rmm2.To.Add(MailTo); Rmm2.AlternateViews.Add(htmlView); Rmm2.IsBodyHtml = true; clientip.Send(Rmm2); Rmm2.To.Clear(); } catch (FormatException ex) { ex.Message.ToString(); return; } catch (SmtpException ex) { ex.Message.ToString(); return; } finally { conn.Close(); } } catch (Exception ex) { ex.Message.ToString(); } }
public FCMNotificationReceivedEventArgs(FCMNotification notification) { Notification = notification; }
public static NotificationCompat.Builder TrySetBigPictureStyle(this NotificationCompat.Builder @this, FCMNotification notification) { try { var bitmap = DecodeBitmap(notification.ImageUrl); return(@this.SetLargeIcon(bitmap).SetStyle(new NotificationCompat.BigPictureStyle().BigPicture(bitmap).BigLargeIcon(null))); } catch (Exception e) { Console.WriteLine($"Couldn't attach image to push notification: {e.Message}"); return(@this); } }
private void SendMail(DO_WallMessage WallMessageDO, string RecieverID) { try { string body = null; DataTable dtUserDetails1 = new DataTable(); DataTable dtUserDetails2 = new DataTable(); objLogin.intRegistartionID = Convert.ToInt32(RecieverID); dtUserDetails1.Clear(); dtUserDetails1 = objLoginDB.GetDataTable(objLogin, DA_SKORKEL.DA_Login.Login_1.UserDetails); objLogin.intRegistartionID = Convert.ToInt32(ViewState["UserID"]); dtUserDetails2.Clear(); dtUserDetails2 = objLoginDB.GetDataTable(objLogin, DA_SKORKEL.DA_Login.Login_1.UserDetails); SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); string mailfrom = ConfigurationManager.AppSettings["mailfrom"]; string mailServer = ConfigurationManager.AppSettings["mailServer"]; string username = ConfigurationManager.AppSettings["UserName"]; string Password = ConfigurationManager.AppSettings["Password"]; string Port = ConfigurationManager.AppSettings["Port"]; string MailURL = ConfigurationManager.AppSettings["MailURL"]; string MailSSL = ConfigurationManager.AppSettings["MailSSL"]; string MailTo = Convert.ToString(dtUserDetails1.Rows[0]["vchrUserName"]); string MailURLFinal = MailURL + "/Inbox.aspx"; string Mailbody = ""; SmtpClient clientip = new SmtpClient(mailServer); clientip.Port = Convert.ToInt32(Port); clientip.UseDefaultCredentials = false; if (MailSSL != "0") { clientip.EnableSsl = true; } clientip.Credentials = new System.Net.NetworkCredential(username, Password); string DisplayName = ConfigurationManager.AppSettings["DisplayName"]; try { MailMessage Rmm2 = new MailMessage(); Rmm2.IsBodyHtml = true; Rmm2.From = new System.Net.Mail.MailAddress(mailfrom, DisplayName); Rmm2.Body = Mailbody.ToString(); using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate.htm"))) { body = reader.ReadToEnd(); } body = body.Replace("{UserName}", Convert.ToString(dtUserDetails1.Rows[0]["LoginName"])); body = body.Replace("{Content}", "<b>" + Convert.ToString(dtUserDetails2.Rows[0]["LoginName"]) + "</b> has sent you a private " + "<a style='color:#01b7bd;text-decoration:none' href='" + MailURLFinal + "'>message</a>"); body = body.Replace("{RedirectURL}", MailURL); System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html); Rmm2.To.Clear(); Rmm2.To.Add(MailTo); Rmm2.Subject = "Private Message from " + Convert.ToString(dtUserDetails2.Rows[0]["LoginName"]); Rmm2.AlternateViews.Add(htmlView); Rmm2.IsBodyHtml = true; clientip.Send(Rmm2); FCMNotification.Send("Private Message from " + Convert.ToString(dtUserDetails2.Rows[0]["LoginName"]), Convert.ToString(dtUserDetails2.Rows[0]["LoginName"]) + " has sent you a private message.", Convert.ToString(dtUserDetails1.Rows[0]["intRegistrationID"]), MailURLFinal); Rmm2.To.Clear(); } catch (FormatException ex) { ex.Message.ToString(); return; } catch (SmtpException ex) { ex.Message.ToString(); return; } finally { conn.Close(); } } catch (Exception ex) { ex.Message.ToString(); } }
//private void SendMail(string To, string UName, string CustPassword) //{ // try // { // SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); // string mailfrom = ConfigurationManager.AppSettings["mailFrom"]; // string mailServer = ConfigurationManager.AppSettings["mailServer"]; // string username = ConfigurationManager.AppSettings["UserName"]; // string Password = ConfigurationManager.AppSettings["Password"]; // string Port = ConfigurationManager.AppSettings["Port"]; // string MailSSL = ConfigurationManager.AppSettings["MailSSL"]; // string MailTo = To; // // MailTo = "*****@*****.**"; // SmtpClient clientip = new SmtpClient(mailServer); // clientip.Port = Convert.ToInt32(Port); // NetworkCredential cre = new NetworkCredential(username, Password); // clientip.UseDefaultCredentials = false; // if (MailSSL != "0") // clientip.EnableSsl = true; // clientip.Credentials = cre; // string DisplayName = ConfigurationManager.AppSettings["DisplayName"]; // try // { // string Topic = string.Empty; // string Description = string.Empty; // string empid = string.Empty; // string str = "<p> Hi , </p>"; // str += "<p> We have created a new Skorkel Account for you. </p>"; // str += "<p> Your account details are: <br /> Email id for login: "******" <br /> Password:"******"</p>"; // str += "<br /> <br /><p><a href='http://115.124.123.151/Landing.aspx' >www.skorkel.com</a> </p>"; // System.Net.Mail.MailMessage mm2 = new System.Net.Mail.MailMessage(); // mm2.From = new System.Net.Mail.MailAddress(mailfrom, DisplayName); // System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(str, null, "text/html"); // mm2.To.Clear(); // mm2.CC.Clear(); // mm2.Bcc.Clear(); // mm2.To.Add(MailTo); // mm2.Subject = "Skorkel - Account created"; // mm2.AlternateViews.Add(htmlView); // mm2.IsBodyHtml = true; // clientip.Send(mm2); // mm2.To.Clear(); // mm2.CC.Clear(); // mm2.Bcc.Clear(); // } // catch (FormatException ex) // { // ex.Message.ToString(); // return; // } // catch (SmtpException ex) // { // ex.Message.ToString(); // return; // } // finally // { // conn.Close(); // } // } // catch (Exception ex) // { // ex.Message.ToString(); // } //} private void SendMail(string userName) { try { DataTable dtRecord = new DataTable(); string body = null; SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); string mailfrom = ConfigurationManager.AppSettings["mailfrom"]; string mailServer = ConfigurationManager.AppSettings["mailServer"]; string username = ConfigurationManager.AppSettings["UserName"]; string Password = ConfigurationManager.AppSettings["Password"]; string Port = ConfigurationManager.AppSettings["Port"]; string MailURL = ConfigurationManager.AppSettings["MailURL"]; string MailSSL = ConfigurationManager.AppSettings["MailSSL"]; string MailTo = userName.Trim(); string Mailbody = ""; SmtpClient clientip = new SmtpClient(mailServer); clientip.Port = Convert.ToInt32(Port); clientip.UseDefaultCredentials = false; if (MailSSL != "0") { clientip.EnableSsl = true; } string id = "id=" + Session["ExternalUserId"]; string encript = QueryStringModule.Encrypt(id.ToString()); clientip.Credentials = new System.Net.NetworkCredential(username, Password); string DisplayName = ConfigurationManager.AppSettings["DisplayName"]; dtRecord.Clear(); objRegistration.UserName = userName; dtRecord = objRegistrationDB.GetDataTableRecord(objRegistration, DA_Registrationdetails.RegistrationDetails.UserRecordByMail); try { MailMessage Rmm2 = new MailMessage(); Rmm2.IsBodyHtml = true; Rmm2.From = new System.Net.Mail.MailAddress(mailfrom, DisplayName); Rmm2.Body = Mailbody.ToString(); using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTemplate.htm"))) { body = reader.ReadToEnd(); } body = body.Replace("{UserName}", Convert.ToString(dtRecord.Rows[0]["vchrFirstName"] + " " + dtRecord.Rows[0]["vchrLastName"])); body = body.Replace("{Content}", "Welcome to Skorkel. Skorkel is a one stop platform for you to - <ul><li>connect with the law student community</li>" + "<li>research and collaborate</li><li>access legal news</li><li>access journals and contribute blogs & articles</li><li>apply for jobs and internships</li></ul>" + "Please click on <a href=" + MailURL + " style='color:#01B7BD; text-decoration: none;'>" + MailURL + "</a> to log in"); body = body.Replace("{RedirectURL}", MailURL); System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html); Rmm2.To.Clear(); Rmm2.To.Add(MailTo); Rmm2.Subject = "Welcome to Skorkel"; Rmm2.AlternateViews.Add(htmlView); Rmm2.IsBodyHtml = true; clientip.Send(Rmm2); FCMNotification.Send("Welcome to Skorkel", "Welcome to Skorkel. Skorkel is a one stop platform for you to - connect with the law student community; research and collaborate; " + "access legal news; access journals and contribute blogs & articles; apply for jobs and internships.", Convert.ToString(dtRecord.Rows[0]["intRegistrationID"]), MailURL); Rmm2.To.Clear(); } catch (FormatException ex) { ex.Message.ToString(); return; } catch (SmtpException ex) { ex.Message.ToString(); return; } finally { conn.Close(); } } catch (Exception ex) { ex.Message.ToString(); } }