private void EnviarEmail(string assunto, string mensagem, string endereco) { EMail eMail = new EMail(); eMail.Client("smtp.gmail.com"); eMail.Port = 587; eMail.FromAddress = "*****@*****.**"; eMail.Acount = "*****@*****.**"; eMail.PassWord = "******"; eMail.EnableSsl = true; eMail.Subject = assunto; eMail.Body = mensagem.Replace("\\n", Environment.NewLine); eMail.AddTo(endereco); try { eMail.Send(); eMail.ClearTo(); } catch (Exception ex) { } }
/// <summary> /// Invite New Users by sending mail. /// </summary> /// <param name="email"></param> /// <param name="infos"></param> /// <returns></returns> public string InviteUsers(string email, List <RolesInfo> infos) { if (string.IsNullOrEmpty(email)) { return(""); } EMail objMail = new EMail(ctx, "", "", "", "", "", "", true, false); string isConfigExist = objMail.IsConfigurationExist(ctx); if (isConfigExist != "OK") { return(isConfigExist); } X_AD_InviteUser iuser = new X_AD_InviteUser(ctx, 0, null); if (iuser.Save()) { for (int i = 0; i < infos.Count; i++) { X_AD_InviteUser_Role userRole = new X_AD_InviteUser_Role(ctx, 0, null); userRole.SetAD_InviteUser_ID(iuser.GetAD_InviteUser_ID()); userRole.SetAD_Role_ID(infos[i].AD_Role_ID); userRole.Save(); } } else { return(Msg.GetMsg(ctx, "VIS_InviteUsernotSaved")); } var emails = email.Split(';'); string url = (HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.Url.AbsolutePath).Substring(0, (HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.Url.AbsolutePath).LastIndexOf("/")); string hostUrl = url.Substring(0, url.LastIndexOf("/")); if (hostUrl.IndexOf("http") == -1) { hostUrl = HttpContext.Current.Request.Url.Scheme + "://" + hostUrl; } if (HttpContext.Current.Request.Url.Port > 0 && HttpContext.Current.Request.Url.Port != 80) { url = url.Substring(0, url.LastIndexOf("/")) + ":" + HttpContext.Current.Request.Url.Port.ToString() + "/Areas/VIS/WebPages/CreateUser.aspx"; hostUrl += ":" + HttpContext.Current.Request.Url.Port.ToString(); } else { url = url.Substring(0, url.LastIndexOf("/")) + "/Areas/VIS/WebPages/CreateUser.aspx"; } string queryString = "?inviteID=" + SecureEngine.Encrypt(iuser.GetAD_InviteUser_ID().ToString()) + "&URL=" + hostUrl + "&lang=" + ctx.GetAD_Language(); if (emails.Length == 1) { queryString += "&mailID=" + SecureEngine.Encrypt(emails[0].ToString()); } else { queryString += "&mailID=0"; } objMail.SetSubject(Msg.GetMsg(ctx, "VIS_CreateUser")); //<label >Hello</label><br>" + // "<label >Please Click to create user with vienna Advantage</label>> string html = " <html><body> " + Msg.GetMsg(ctx, "VIS_InviteMailMessage") + " <br>" + "<a href='http://" + url + queryString + "'>click here </a> </body></html> "; objMail.SetMessageHTML(html); for (int i = 0; i < emails.Count(); i++) { objMail.AddTo(emails[i], ""); } string res1 = objMail.Send(); StringBuilder res = new StringBuilder(); if (res1 != "OK") // if mail not sent.... { if (res1 == "AuthenticationFailed.") { res.Append("AuthenticationFailed"); return(res.ToString()); } else if (res1 == "ConfigurationIncompleteOrNotFound") { res.Append("ConfigurationIncompleteOrNotFound"); return(res.ToString()); } else { res.Append(" " + Msg.GetMsg(ctx, "MailNotSentTo") + ": " + email); } } else { { if (!res.ToString().Contains("MailSent")) { res.Append("MailSent"); } } } return(res.ToString()); }
public void SendEmailOrNotification(Ctx ctx, int userID, bool isEmail, bool isNotification, bool isBoth, int tableid, StringBuilder strBuilder, string message, int recordID, string searchKey) { //******************Temporary Commented****************** // VAdvantage.Classes.Context ctx = new VAdvantage.Classes.Context(ctxmap); string emailID = Convert.ToString(DB.ExecuteScalar("SELECT EMAIL FROM AD_USER WHERE AD_USER_ID=" + userID)); message += " (" + searchKey + ")"; try { if (isEmail) { // log.Log(Level.SEVERE, "SendOnlyEmailToSubscribeUser"); // VAdvantage.Logging.VLogger.Get().Info("SendOnlyEmailToSubscribeUser"); // VAdvantage.Utility.EMail objEmail = new VAdvantage.Utility.EMail(ctx, string.Empty, string.Empty, string.Empty, string.Empty, Msg.GetMsg(ctx, "VADMS_FolderSubscriptionNotification"), message,false,true); VAdvantage.Utility.EMail objEmail = new EMail(ctx, string.Empty, string.Empty, string.Empty, string.Empty, "AttachEmailNotification", message, false, true); if (emailID.IndexOf(";") > -1) { string[] eIDS = emailID.Split(';'); for (int k = 0; k < eIDS.Length; k++) { objEmail.AddTo(eIDS[k], ""); } } else { objEmail.AddTo(emailID, ""); } objEmail.SetMessageText(message); objEmail.SetSubject("AttachEmailNotification"); string resu = objEmail.Send(); } else if (isNotification) { // log.Log(Level.SEVERE, "SendOnlyNoticeToSubscribeUser"); MNote note = new MNote(ctx, 0, null); note.SetAD_User_ID(userID); // changes done by Bharat on 22 May 2018 to set Organization to * on Notification as discussed with Mukesh Sir. //note.SetClientOrg(ctx.GetAD_Client_ID(), ctx.GetAD_Org_ID()); note.SetClientOrg(ctx.GetAD_Client_ID(), 0); note.SetTextMsg(message); note.SetDescription(Msg.GetMsg(ctx, "AttachEmailNotification")); note.SetRecord(tableid, recordID); // point to this note.SetAD_Message_ID(859); //Workflow if (!note.Save()) { // CreateMessage(strBuilder, Convert.ToString(recordID)); } } else if (isBoth) { // log.Log(Level.SEVERE, "SendOnlyEmailAndNoticeToSubscribeUser"); VAdvantage.Utility.EMail objEmail = new VAdvantage.Utility.EMail(ctx, string.Empty, string.Empty, string.Empty, string.Empty, Msg.GetMsg(ctx, "AttachEmailNotification"), message, false, true); // VAdvantage.Utility.EMail objEmail = new EMail(ctx, string.Empty, string.Empty, emailID, string.Empty, Msg.GetMsg(ctx, "VADMS_FolderSubscriptionNotification"), message, false, true); if (emailID.IndexOf(";") > -1) { string[] eIDS = emailID.Split(';'); for (int k = 0; k < eIDS.Length; k++) { objEmail.AddTo(eIDS[k], ""); } } else { objEmail.AddTo(emailID, ""); } objEmail.SetMessageText(message); objEmail.SetSubject(Msg.GetMsg(ctx, "AttachEmailNotification")); objEmail.Send(); MNote note = new MNote(ctx, 0, null); note.SetAD_User_ID(userID); // changes done by Bharat on 22 May 2018 to set Organization to * on Notification as discussed with Mukesh Sir. //note.SetClientOrg(ctx.GetAD_Client_ID(), ctx.GetAD_Org_ID()); note.SetClientOrg(ctx.GetAD_Client_ID(), 0); note.SetTextMsg(message); note.SetDescription(Msg.GetMsg(ctx, "AttachEmailNotification")); note.SetRecord(tableid, recordID); // point to this note.SetAD_Message_ID(859); //Workflow if (!note.Save()) { // CreateMessage(strBuilder, Convert.ToString(recordID)); } } } catch (Exception ex) { VAdvantage.Logging.VLogger.Get().Info(ex.Message); log.Severe("SendEmailOrNotification Error : " + ex.Message); } //*************************************** }