Ejemplo n.º 1
0
        /// <summary>
        /// Used to send mails .... Fetechs credentails used to send mails...
        /// </summary>
        /// <param name="mails"></param>
        /// <param name="AD_User_ID"></param>
        /// <param name="AD_Client_ID"></param>
        /// <param name="AD_Org_ID"></param>
        /// <param name="attachment_ID"></param>
        /// <param name="fileNames"></param>
        /// <param name="fileNameForOpenFormat"></param>
        /// <param name="mailFormat"></param>
        /// <param name="notify"></param>
        /// <returns></returns>
        public string SendMails(List <NewMailMessage> mails, int AD_User_ID, int AD_Client_ID, int AD_Org_ID, int attachment_ID, List <string> fileNames, List <string> fileNameForOpenFormat, string mailFormat, bool notify, List <int> lstDocumentIds)
        {
            VAdvantage.Utility.EMail sendmail = new VAdvantage.Utility.EMail(ctx, "", "", "", "", "", "",
                                                                             true, false);
            string isConfigExist = sendmail.IsConfigurationExist(ctx);

            if (isConfigExist != "OK")
            {
                return(isConfigExist);
            }

            sendmail = null;


            if (notify)//if want to send mail on server and want notice on home screen.     Else u have to wait, and it will show alert message of return value....
            {
                System.Threading.ThreadPool.QueueUserWorkItem(delegate
                {
                    SendMailstart(mails, AD_User_ID, AD_Client_ID, AD_Org_ID, attachment_ID, fileNames, fileNameForOpenFormat, mailFormat, notify, sendmail, lstDocumentIds);
                });
                return("");
            }
            else
            {
                return(SendMailstart(mails, AD_User_ID, AD_Client_ID, AD_Org_ID, attachment_ID, fileNames, fileNameForOpenFormat, mailFormat, notify, sendmail, lstDocumentIds));
            }
        }
        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);
        }