コード例 #1
0
        }       //	sendNoGuaranteeMail

        /// <summary>
        /// Deliver Asset
        /// </summary>
        /// <param name="A_Asset_ID">asset</param>
        /// <returns>message - delivery errors start with **</returns>
        private String DeliverIt(int A_Asset_ID)
        {
            log.Fine("A_Asset_ID=" + A_Asset_ID);
            long start = CommonFunctions.CurrentTimeMillis();
            //
            MAsset asset = new MAsset(GetCtx(), A_Asset_ID, Get_Trx());

            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 (asset.GetProductR_MailText_ID() == 0)
            {
                return("** Product Mail Text");
            }
            if (_MailText == null || _MailText.GetR_MailText_ID() != asset.GetProductR_MailText_ID())
            {
                _MailText = new VAdvantage.Model.MMailText(GetCtx(), asset.GetProductR_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 || !email.IsValid())
            {
                asset.SetHelp(asset.GetHelp() + " - Invalid EMail");
                asset.SetIsActive(false);
                return("** Invalid EMail: " + user.GetEMail() + " - " + email);
            }
            if (_client.IsSmtpAuthorization())
            {
                email.CreateAuthenticator(_client.GetRequestUser(), _client.GetRequestUserPW());
            }
            _MailText.SetUser(user);
            _MailText.SetPO(asset);
            String message = _MailText.GetMailText(true);

            if (_MailText.IsHtml() || _AttachAsset)
            {
                email.SetMessageHTML(_MailText.GetMailHeader(), message);
            }
            else
            {
                email.SetSubject(_MailText.GetMailHeader());
                email.SetMessageText(message);
            }
            if (_AttachAsset)
            {
                MProductDownload[] pdls = asset.GetProductDownloads();
                if (pdls != null)
                {
                    foreach (MProductDownload element in pdls)
                    {
                        //URL url = element.getDownloadURL(m_client.getDocumentDir());
                        Url url = element.GetDownloadURL(_client.GetDocumentDir());
                        if (url != null)
                        {
                            email.AddAttachment(url.Value);
                        }
                    }
                }
                else
                {
                    log.Warning("No DowloadURL for A_Asset_ID=" + A_Asset_ID);
                }
            }
            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);
            }

            MAssetDelivery ad = asset.ConfirmDelivery(email, user.GetAD_User_ID());

            ad.Save();
            asset.Save();
            //
            log.Fine((CommonFunctions.CurrentTimeMillis() - start) + " ms");
            //	success
            return(user.GetEMail() + " - " + asset.GetProductVersionNo());
        }