}       //	doIt

        /// <summary>
        /// Send No Guarantee EMail
        /// </summary>
        /// <param name="A_Asset_ID">asset</param>
        /// <param name="R_MailText_ID">mail to send</param>
        /// <param name="trxName">trx</param>
        /// <returns>message - delivery errors start with **</returns>
        private String SendNoGuaranteeMail(int A_Asset_ID, int R_MailText_ID, Trx trxName)
        {
            MAsset asset = new MAsset(GetCtx(), A_Asset_ID, trxName);

            if (asset.GetAD_User_ID() == 0)
            {
                return("** No Asset User");
            }
            VAdvantage.Model.MUser user = new VAdvantage.Model.MUser(GetCtx(), asset.GetAD_User_ID(), Get_Trx());
            if (user.GetEMail() == null || user.GetEMail().Length == 0)
            {
                return("** No Asset User Email");
            }
            if (_MailText == null || _MailText.GetR_MailText_ID() != R_MailText_ID)
            {
                _MailText = new VAdvantage.Model.MMailText(GetCtx(), R_MailText_ID, Get_Trx());
            }
            if (_MailText.GetMailHeader() == null || _MailText.GetMailHeader().Length == 0)
            {
                return("** No Subject");
            }

            //	Create Mail
            EMail email = _client.CreateEMail(user.GetEMail(), user.GetName(), null, null);

            if (email == null)
            {
                return("** Invalid: " + user.GetEMail());
            }
            _MailText.SetPO(user);
            _MailText.SetPO(asset);
            String message = _MailText.GetMailText(true);

            if (_MailText.IsHtml())
            {
                email.SetMessageHTML(_MailText.GetMailHeader(), message);
            }
            else
            {
                email.SetSubject(_MailText.GetMailHeader());
                email.SetMessageText(message);
            }
            String msg = email.Send();

            new MUserMail(_MailText, asset.GetAD_User_ID(), email).Save();
            if (!EMail.SENT_OK.Equals(msg))
            {
                return("** Not delivered: " + user.GetEMail() + " - " + msg);
            }
            //
            return(user.GetEMail());
        }       //	sendNoGuaranteeMail
        /// <summary>
        ///     Send RfQ, mail subject and body from mail template
        /// </summary>
        /// <returns>true if RfQ is sent per email.</returns>
        public bool SendRfQ()
        {
            try
            {
                MUser     to     = MUser.Get(GetCtx(), GetAD_User_ID());
                MClient   client = MClient.Get(GetCtx());
                MMailText mtext  = new MMailText(GetCtx(), GetRfQ().GetR_MailText_ID(), Get_TrxName());

                if (to.Get_ID() == 0 || to.GetEMail() == null || to.GetEMail().Length == 0)
                {
                    log.Log(Level.SEVERE, "No User or no EMail - " + to);
                    return(false);
                }

                // Check if mail template is set for RfQ window, if not then get from RfQ Topic window.
                if (mtext.GetR_MailText_ID() == 0)
                {
                    MRfQTopic mRfQTopic = new MRfQTopic(GetCtx(), GetRfQ().GetC_RfQ_Topic_ID(), Get_TrxName());
                    if (mRfQTopic.GetC_RfQ_Topic_ID() > 0)
                    {
                        mtext = new MMailText(GetCtx(), mRfQTopic.GetR_MailText_ID(), Get_TrxName());
                    }
                }

                //Replace the email template constants with tables values.
                StringBuilder message = new StringBuilder();
                mtext.SetPO(GetRfQ(), true);
                message.Append(mtext.GetMailText(true).Equals(string.Empty) ? "** No Email Body" : mtext.GetMailText(true));

                String subject = String.IsNullOrEmpty(mtext.GetMailHeader()) ? "** No Subject" : mtext.GetMailHeader();;

                EMail email = client.CreateEMail(to.GetEMail(), to.GetName(), subject, message.ToString());
                if (email == null)
                {
                    return(false);
                }
                email.AddAttachment(CreatePDF());
                if (EMail.SENT_OK.Equals(email.Send()))
                {
                    //SetDateInvited(new Timestamp(System.currentTimeMillis()));
                    SetDateInvited(DateTime.Now);
                    Save();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                log.Severe(ex.ToString());
                //MessageBox.Show("error--" + ex.ToString());
            }
            return(false);
        }
Exemple #3
0
 /// <summary>
 ///     Send RfQ
 /// </summary>
 /// <returns>true if RfQ is sent per email.</returns>
 public bool SendRfQ()
 {
     try
     {
         MUser to = MUser.Get(GetCtx(), GetAD_User_ID());
         if (to.Get_ID() == 0 || to.GetEMail() == null || to.GetEMail().Length == 0)
         {
             log.Log(Level.SEVERE, "No User or no EMail - " + to);
             return(false);
         }
         MClient client = MClient.Get(GetCtx());
         //
         String message = GetDescription();
         if (message == null || message.Length == 0)
         {
             message = GetHelp();
         }
         else if (GetHelp() != null)
         {
             message += "\n" + GetHelp();
         }
         if (message == null)
         {
             message = GetName();
         }
         //
         EMail email = client.CreateEMail(to.GetEMail(), to.GetName(), "RfQ: " + GetName(), message);
         if (email == null)
         {
             return(false);
         }
         email.AddAttachment(CreatePDF());
         if (EMail.SENT_OK.Equals(email.Send()))
         {
             //SetDateInvited(new Timestamp(System.currentTimeMillis()));
             SetDateInvited(DateTime.Now);
             Save();
             return(true);
         }
     }
     catch (Exception ex)
     {
         log.Severe(ex.ToString());
         //MessageBox.Show("error--" + ex.ToString());
     }
     return(false);
 }