private void FetchRecordsAttachment(EMail email, int AD_Table_ID, int Record_ID) { MAttachment mAttach = MAttachment.Get(p_ctx, AD_Table_ID, Record_ID); string filePath = ""; //System.IO.Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "TempDownload"); 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); email.AddAttachment(new FileInfo(filePath)); } } else { foreach (MAttachmentEntry entry in mAttach.GetEntries()) { email.AddAttachment(entry.GetData(), entry.GetName()); } } }
/// <summary> /// /// </summary> /// <param name="toEMail"></param> /// <param name="toName"></param> /// <param name="subject"></param> /// <param name="message"></param> /// <param name="attachment"></param> /// <returns></returns> public bool SendEMail(String toEMail, String toName, String subject, String message, FileInfo attachment) { EMail email = CreateEMail(toEMail, toName, subject, message); if (email == null) { return(false); } if (attachment != null) { email.AddAttachment(attachment); } try { String msg = email.Send(); if (EMail.SENT_OK.Equals(msg)) { //log.info("Sent EMail " + subject + " to " + toEMail); return(true); } else { //log.warning("Could NOT Send Email: " + subject + " to " + toEMail + ": " + msg + " (" + GetName() + ")"); return(false); } } catch { //log.severe(GetName() + " - " + ex.Message); return(false); } }
/// <summary> /// /// </summary> /// <param name="AD_User_ID"></param> /// <param name="subject"></param> /// <param name="message"></param> /// <param name="attachment"></param> /// <returns></returns> public bool SendEMail(int AD_User_ID, String subject, String message, FileInfo attachment) { MUser to = MUser.Get(GetCtx(), AD_User_ID); String toEMail = to.GetEMail(); if (toEMail == null || toEMail.Length == 0) { //log.warning("No EMail for recipient: " + to); return(false); } if (to.IsEMailBounced()) { //log.warning("EMail bounced for recipient: " + to); return(false); } EMail email = CreateEMail(null, to, subject, message); if (email == null) { return(false); } if (attachment != null) { email.AddAttachment(attachment); } try { return(SendEmailNow(null, to, email)); } catch (Exception ex) { log.Severe(GetName() + " - " + ex.Message); return(false); } }
/// <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); }
public bool SendEMail(String toEMail, String toName, String subject, String message, FileInfo attachment, bool isHtml, int AD_Table_ID, int Record_ID, byte[] array = null, String fileName = "Rpt.pdf") { EMail email = CreateEMail(toEMail, toName, subject, message, isHtml); if (email == null) { return(false); } if (attachment != null) { email.AddAttachment(attachment); } if (array != null) { email.AddAttachment(array, fileName); } FetchRecordsAttachment(email, AD_Table_ID, Record_ID); try { String msg = email.Send(); if (EMail.SENT_OK.Equals(msg)) { //log.info("Sent EMail " + subject + " to " + toEMail); return(true); } else { //log.warning("Could NOT Send Email: " + subject + " to " + toEMail + ": " + msg + " (" + GetName() + ")"); return(false); } } catch (Exception ex) { log.Severe(GetName() + " - " + ex.Message); return(false); } }
/// <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); }
public bool SendEMail(PO from, PO to, String subject, String message, FileInfo attachment) { EMail email = CreateEMail(from, to, subject, message); if (email == null) { return(false); } if (attachment != null) { email.AddAttachment(attachment); } MailAddress emailFrom = email.GetFrom(); try { return(SendEmailNow(from, to, email)); } catch { //log.severe(GetName() + " - from " + emailFrom + " to " + to + ": " + ex.Message); return(false); } }
public bool SendEMail(MUser from, MUser to, String subject, String message, FileInfo attachment, bool isHTML) { EMail email = CreateEMail(from, to, subject, message, isHTML); if (email == null) { return(false); } if (attachment != null) { email.AddAttachment(attachment); } MailAddress emailFrom = email.GetFrom(); try { return(SendEmailNow(from, to, email)); } catch (Exception ex) { log.Severe(GetName() + " - from " + emailFrom + " to " + to + ": " + ex.Message); return(false); } }
/// <summary> /// Process /// </summary> /// <returns>info</returns> protected override String DoIt() { log.Info("C_DunningRun_ID=" + _C_DunningRun_ID + ",R_MailText_ID=" + _R_MailText_ID + ", EmailPDF=" + _EMailPDF + ",IsOnlyIfBPBalance=" + _IsOnlyIfBPBalance); // Need to have Template if (_EMailPDF && _R_MailText_ID == 0) { throw new Exception("@NotFound@: @R_MailText_ID@"); } String subject = ""; MMailText mText = null; if (_EMailPDF) { mText = new MMailText(GetCtx(), _R_MailText_ID, Get_TrxName()); if (_EMailPDF && mText.Get_ID() == 0) { throw new Exception("@NotFound@: @R_MailText_ID@ - " + _R_MailText_ID); } subject = mText.GetMailHeader(); } // MDunningRun run = new MDunningRun(GetCtx(), _C_DunningRun_ID, Get_TrxName()); if (run.Get_ID() == 0) { throw new Exception("@NotFound@: @C_DunningRun_ID@ - " + _C_DunningRun_ID); } // Print Format on Dunning Level MDunningLevel level = new MDunningLevel(GetCtx(), run.GetC_DunningLevel_ID(), Get_TrxName()); MPrintFormat format = MPrintFormat.Get(GetCtx(), level.GetDunning_PrintFormat_ID(), false); MClient client = MClient.Get(GetCtx()); int count = 0; int errors = 0; MDunningRunEntry[] entries = run.GetEntries(false); for (int i = 0; i < entries.Length; i++) { MDunningRunEntry entry = entries[i]; if (_IsOnlyIfBPBalance && Env.Signum(entry.GetAmt()) <= 0) { continue; } // To BPartner MBPartner bp = new MBPartner(GetCtx(), entry.GetC_BPartner_ID(), Get_TrxName()); if (bp.Get_ID() == 0) { AddLog(entry.Get_ID(), null, null, "@NotFound@: @C_BPartner_ID@ " + entry.GetC_BPartner_ID()); errors++; continue; } // To User MUser to = new MUser(GetCtx(), entry.GetAD_User_ID(), Get_TrxName()); if (_EMailPDF) { if (to.Get_ID() == 0) { AddLog(entry.Get_ID(), null, null, "@NotFound@: @AD_User_ID@ - " + bp.GetName()); errors++; continue; } else if (to.GetEMail() == null || to.GetEMail().Length == 0) { AddLog(entry.Get_ID(), null, null, "@NotFound@: @EMail@ - " + to.GetName()); errors++; continue; } } // BP Language //Language language =Language.getLoginLanguage(); // Base Language Language language = Env.GetLoginLanguage(GetCtx()); String tableName = "C_Dunning_Header_v"; if (client.IsMultiLingualDocument()) { tableName += "t"; String AD_Language = bp.GetAD_Language(); if (AD_Language != null) { //language =language.getLanguage(AD_Language); } } // format.SetLanguage(language); // format.SetTranslationLanguage(language); // query Query query = new Query(tableName); query.AddRestriction("C_DunningRunEntry_ID", Query.EQUAL, entry.GetC_DunningRunEntry_ID()); // Engine //PrintInfo info = new PrintInfo( // bp.GetName(), // X_C_DunningRunEntry.Table_ID, // entry.GetC_DunningRunEntry_ID(), // entry.GetC_BPartner_ID()); //info.SetDescription(bp.GetName() + ", Amt=" + entry.GetAmt()); //ReportEngine re = new ReportEngine(GetCtx(), format, query, info); byte[] pdfReport; string reportPath = ""; bool printed = false; if (_EMailPDF) { EMail email = client.CreateEMail(to.GetEMail(), to.GetName(), null, null); if (email == null || !email.IsValid()) { AddLog(entry.Get_ID(), null, null, "@RequestActionEMailError@ Invalid EMail: " + to); errors++; continue; } mText.SetUser(to); // variable context mText.SetBPartner(bp); mText.SetPO(entry); String message = mText.GetMailText(true); if (mText.IsHtml()) { email.SetMessageHTML(mText.GetMailHeader(), message); } else { email.SetSubject(mText.GetMailHeader()); email.SetMessageText(message); } // //File attachment = re.GetPDF(File.createTempFile("Dunning", ".pdf")); //log.Fine(to + " - " + attachment); //email.AddAttachment(attachment); // // Get report that is bound on the dunning entry tab of dunning run window. int ReportProcess_ID = Util.GetValueOfInt(DB.ExecuteScalar("SELECT AD_Process_ID FROM ad_tab WHERE export_id='VIS_634'")); if (ReportProcess_ID > 0) { Common.Common Com = new Common.Common(); Dictionary <string, object> d = Com.GetReport(GetCtx(), ReportProcess_ID, "C_DunningRunEntry", X_C_DunningRunEntry.Table_ID, entry.GetC_DunningRunEntry_ID(), 0, "", FileType, out pdfReport, out reportPath); if (pdfReport != null) { email.AddAttachment(pdfReport, "Dunning" + entry.GetC_DunningRunEntry_ID() + ".pdf"); } } String msg = email.Send(); MUserMail um = new MUserMail(mText, entry.GetAD_User_ID(), email); um.Save(); if (msg.Equals(EMail.SENT_OK)) { AddLog(entry.Get_ID(), null, null, bp.GetName() + " @RequestActionEMailOK@"); count++; printed = true; } else { AddLog(entry.Get_ID(), null, null, bp.GetName() + " @RequestActionEMailError@ " + msg); errors++; } } else { //re.print(); count++; printed = true; } if (printed) { entry.SetProcessed(true); entry.Save(); DunningLevelConsequences(level, entry); } } // for all dunning letters if (errors == 0) { run.SetProcessed(true); run.Save(); } if (_EMailPDF) { return("@Sent@=" + count + " - @Errors@=" + errors); } return("@Printed@=" + count); }
} // 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()); }