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); } //*************************************** }
private string SendEmailWithAttachment(string Subject, string Message, DataSet ds1, int AD_Org_ID, int Ad_Client_ID) { string Check = ""; int count = 0; string res = ""; List <string> EmailLst = new List <string>(); //!string.IsNullOrEmpty(EmailIDs) ? EmailIDs.Split(',').ToList() : null; int UpdatedBy = GetCtx().GetAD_User_ID(); sendmail = new VAdvantage.Utility.EMail(GetCtx(), "", "", "", "", "", "", true, false); string isConfigExist = sendmail.IsConfigurationExist(GetCtx()); if (isConfigExist != "OK") { log.SaveError("Check email configuration", ""); return(Msg.GetMsg(GetCtx(), "VIS_CheckMailConfig")); } if (ds1 != null && ds1.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds1.Tables[0].Rows.Count; i++) { if (Util.GetValueOfString(ds1.Tables[0].Rows[i]["NOTIFICATIONTYPE"]) == "A" || Util.GetValueOfString(ds1.Tables[0].Rows[i]["NOTIFICATIONTYPE"]) == "B" || Util.GetValueOfString(ds1.Tables[0].Rows[i]["NOTIFICATIONTYPE"]) == "E" || Util.GetValueOfString(ds1.Tables[0].Rows[i]["NOTIFICATIONTYPE"]) == "L") { sendmail.AddBcc(Util.GetValueOfString(ds1.Tables[0].Rows[i]["EMAIL"])); } } sendmail.SetSubject(Subject); sendmail.SetMessageText(Message); MAttachment mAttach = GetFileAttachment(GetTable_ID(), GetRecord_ID(), GetCtx()); string filePath = ""; if (mAttach != null && mAttach.AD_Attachment_ID > 0) { if (mAttach == null) { return(""); } if (mAttach.IsFromHTML()) { for (int i = 0; i < mAttach._lines.Count; i++) { filePath = System.IO.Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "TempDownload"); filePath = System.IO.Path.Combine(filePath, mAttach.GetFile(mAttach._lines[i].Line_ID)); if (filePath.IndexOf("ERROR") > -1) { continue; } filePath = System.IO.Path.Combine(filePath, mAttach._lines[i].FileName); sendmail.AddAttachment(new FileInfo(filePath)); } } else { foreach (MAttachmentEntry entry in mAttach.GetEntries()) { sendmail.AddAttachment(entry.GetData(), entry.GetName()); } } } Check = sendmail.Send(); if (Check == "OK") { count++; } } if (ds1 != null && ds1.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds1.Tables[0].Rows.Count; i++) { if (Util.GetValueOfString(ds1.Tables[0].Rows[i]["NOTIFICATIONTYPE"]) == "B" || Util.GetValueOfString(ds1.Tables[0].Rows[i]["NOTIFICATIONTYPE"]) == "C" || Util.GetValueOfString(ds1.Tables[0].Rows[i]["NOTIFICATIONTYPE"]) == "N") { SendNotice(Message, Util.GetValueOfInt(ds1.Tables[0].Rows[i]["AD_USER_ID"]), AD_Org_ID, Ad_Client_ID); } } } if (count > 0) { log.Fine("Email Sent Successfully"); res = Msg.GetMsg(GetCtx(), "VIS_EmailSent"); string sql = "UPDATE OFFICEMEMO SET PUBLISHDATE = " + GlobalVariable.TO_DATE(System.DateTime.Now, false) + ", PUBLISHTIME = " + GlobalVariable.TO_DATE(System.DateTime.Now, false) + ", PROCESSED = 'Y' WHERE OFFICEMEMO_ID = " + _OfficeMemoID; DB.ExecuteQuery(sql, null, null); } else { log.SaveError("Email Not Sent", ""); res = Msg.GetMsg(GetCtx(), "VIS_EmailNotSent"); } return(res); }