private IMailTextBuilder createMailTextBuilder( final I_C_RfQResponse rfqResponse, final RfQReportType rfqReportType) { final I_C_RfQ_Topic rfqTopic = rfqResponse.getC_RfQ().getC_RfQ_Topic(); final IMailTextBuilder mailTextBuilder; if (rfqReportType == RfQReportType.Invitation) { mailTextBuilder = mailBL.newMailTextBuilder(rfqTopic.getRfQ_Invitation_MailText()); } else if (rfqReportType == RfQReportType.InvitationWithoutQtyRequired) { mailTextBuilder = mailBL.newMailTextBuilder(rfqTopic.getRfQ_InvitationWithoutQty_MailText()); } else if (rfqReportType == RfQReportType.Won) { mailTextBuilder = mailBL.newMailTextBuilder(rfqTopic.getRfQ_Win_MailText()); } else if (rfqReportType == RfQReportType.Lost) { mailTextBuilder = mailBL.newMailTextBuilder(rfqTopic.getRfQ_Lost_MailText()); } else { throw new AdempiereException("@Invalid@ @Type@: " + rfqReportType); } mailTextBuilder.setC_BPartner(rfqResponse.getC_BPartner()); mailTextBuilder.setAD_User(rfqResponse.getAD_User()); mailTextBuilder.setRecord(rfqResponse); return mailTextBuilder; }
public void publish0( final RfQResponsePublisherRequest request, final RfQReportType rfqReportType) { final I_C_RfQResponse rfqResponse = request.getC_RfQResponse(); // // Check and get the user's mail where we will send the email to final I_AD_User userTo = rfqResponse.getAD_User(); if (userTo == null) { throw new RfQPublishException(request, "@NotFound@ @AD_User_ID@"); } final String userToEmail = userTo.getEMail(); if (Check.isEmpty(userToEmail, true)) { throw new RfQPublishException(request, "@NotFound@ @AD_User_ID@ @Email@ - " + userTo); } // final IMailTextBuilder mailTextBuilder = createMailTextBuilder(rfqResponse, rfqReportType); // final String subject = mailTextBuilder.getMailHeader(); final String message = mailTextBuilder.getFullMailText(); final DefaultModelArchiver archiver = DefaultModelArchiver.of(rfqResponse) .setAD_PrintFormat_ID(getAD_PrintFormat_ID(rfqResponse, rfqReportType)); final I_AD_Archive pdfArchive = archiver.archive(); final byte[] pdfData = archiver.getPdfData(); // // Send it final EMail email = mailBL.createEMail( rfqResponse.getAD_Client() // , (String) null // mailCustomType , (I_AD_User) null // from , userToEmail // to , subject, message, mailTextBuilder.isHtml() // html ); email.addAttachment("RfQ_" + rfqResponse.getC_RfQResponse_ID() + ".pdf", pdfData); final EMailSentStatus emailSentStatus = email.send(); // // Fire mail sent/not sent event (even if there were some errors) { final InternetAddress from = email.getFrom(); final String fromStr = from == null ? null : from.toString(); final InternetAddress to = email.getTo(); final String toStr = to == null ? null : to.getAddress(); archiveEventManager.fireEmailSent( pdfArchive // archive , X_C_Doc_Outbound_Log_Line.ACTION_EMail // action , (I_AD_User) null // user , fromStr // from , toStr // to , (String) null // cc , (String) null // bcc , emailSentStatus.getSentMsg() // status ); } // // Update RfQ response (if success) if (emailSentStatus.isSentOK()) { rfqResponse.setDateInvited(new Timestamp(System.currentTimeMillis())); InterfaceWrapperHelper.save(rfqResponse); } else { throw new RfQPublishException(request, emailSentStatus.getSentMsg()); } }