Jenkins render email-ext template to use for other purpose - jenkins

I have an html email template the represents my pipeline result.
I'm sending the render template by:
emailext body: '${SCRIPT, template="feedback.template"}',
subject: "Full pipeline details",
mimeType: 'text/html',
to: "${config.to}"
I try to send the rendered html report also via slack by:
slackUploadFile filePath: "<MY-rendered-html>", initialComment: "Full Report"
I can't figure out how to get the rendered email-template html for other purpose like sending the html via slack or uploading it to somewhere else

You can use saveOutput: true option

Related

EmailExt- Jenkinsfile - HTML and CSS files are not embedded

EmailExt- Jenkinsfile - HTML and CSS files are not embedded
I am trying to attach html report in the email body and send the mail using Email-ext plugin.
email-ext attachmentsPattern: "filePathToBeAttached", mimeType:'text/html', body: readFile("${env.WORKSPACE}/path_to_report.html"),to: acbd#gmail.com", subject:"test report"
But I could see plain HTML without proper formatting and absence of CSS styling in the email report sent.
Any help pls.
This is currently working for me. HTML is properly formatted in the mail, in outlook. I'm not using any css.
unsuccessful {
emailext mimeType: 'text/html',
subject: "${PROJECT_NAME} - Build # ${BUILD_NUMBER} - ${BUILD_STATUS}!",
body: readFile("${env.WORKSPACE}/JenkinsMailBody.html"),
from: 'noreply-jenkins#sofico.be',
replyTo: 'noreply-jenkins#sofico.be',
recipientProviders: [culprits(), requestor()]
}

HTML file path is coming in the Email body instead of HTML file content in Jenkins using Email-ext

I am giving the below option in Jenkins,
Post-build Actions:
Content Type: HTML (text/html)
Default Subject: $DEFAULT_SUBJECT
Default Content: ${FILE,path="c:/aaa/bbb/ccc/report.html”}
But if I check the email received via jenkins, its showing the file path in the email body as '${FILE,path="c:/aaa/bbb/ccc/report.html”}' instead of actually displaying the content inside the HTML file

Jenkins EmailExt Plugin with both variables and a html body

Below is my jenkins pipeline to send a email
The problem is i have some params.variables in my body which i need to use in order for them to be replaced i need to use """
I also have a HTML file which i attach in the body, for which i need to use ' '
Is there any way to combine both of them in the body? Below code gives UNEXPECTED TOKEN FILE, if i replace " with ' , then the params variable is not replaced
emailext (
mimeType: "text/html",
to: 'srav',
subject: "Job '${env.JOB_BASE_NAME}' (${env.BUILD_NUMBER}) is waiting for approval",
body: """<p>Hi</p><p>Defect ${params.DE_NUMBER} is waiting for approval</p><p>${FILE,path="/atm/com/def/de_1886.html"}</p><p>Please go to console output of "${env.BUILD_URL}input" to <font color="green"> Approve</font> or <font color="red">Reject</font> </p><p>Thank You</p><p>DEVOPS TEAM</p>""",
recipientProviders: [[$class: 'DevelopersRecipientProvider'],[$class: 'RequesterRecipientProvider']]
)

Rails 4/5 Sending Dynamic ActionMailer::Base.mail email With Attachment labeled Noname

I've taken a look at similar posts that mostly deal with sending an attachment by creating a view and controller, such as:
PDF attachment in email is called 'Noname'
but I've got a process that generates files in the background dynamically and need to attach it to a recipient list using ActionMailer::Base.mail. Below is the code:
def send_email(connection)
email = ActionMailer::Base.mail(to: connection['to'], from: connection['from'], subject: 'Sample File', body: "<p>Hello,</p><p>Your data is ready</p>", content_type: 'multipart/mixed')
email.cc = connection['cc'] if connection['cc'].present?
email.bcc = connection['bcc'] if connection['bcc'].present?
#files.each do |file|
report_file_name = "#{#start_time.strftime('%Y%M%dT%I%m%s')}_#{file[0]}.xlsx"
file_location = "#{Rails.root}/tmp/#{report_file_name}"
email.attachments[report_file_name] = File.open(file_location, 'rb'){|f| f.read}
end
email.deliver if email
end
I can see in the logs that it's sending with the content but assume it's sending as Noname because it can't find the view. Any way to get this to work successfully?
Below is the sample output:
Sent mail to sample#sample.com (383.9ms) Date:
Thu, 13 Oct 2016 08:47:30 -0400 From: Sample To:
Recipient Message-ID:
<57ff326270f15_421f1173954919e2#ulinux.mail> Subject: Sample File
Mime-Version: 1.0 Content-Type: multipart/mixed; charset=UTF-8
Content-Transfer-Encoding: 7bit
-- Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;
filename=20161012T08101476259208_Data.xlsx
Content-Transfer-Encoding: base64 Content-Disposition: attachment;
filename=20161012T08101476259208_Data.xlsx Content-ID:
<57ff326270f15_421f1173954919e2#ulinux.mail>
UEsDBBQAAAAIAO.. ... ...ADUFQAAAAA=
Update - I noticed if I use email.content_type = 'text/plain' - the attachment comes through successfully. For me, this works, though I'd appreciate later being able to style my emails with HTML
I presume this works because it prevents Rails from its usual gleaning/autointerpreting process. I'd certainly like to see a multipart/mixed or html compatible version work here though.
Update 2 This only fixed the issue artificially in the rails_email_preview gem, which renders the emails to a new tab in development. In production, this simply and understandably prints the details and the presumably base64-encoded file, so question remains open.
I have meet this problem too, after some investigation, it seems in Rails 4, you can't call attachments method after calling mail method, otherwise the content_type of the mail message object won't have boundary information so that the attachments part can't be parsed correctly in the received email.
I think digging into the actionmailer source code and you should be able to find a solution, either by override the default mail method or set the correct boundary info manually.
But for quick resolving this problem, I thought out a not elegant work around by using meta programming: define a delegation class which inherits ActionMailer::Base.
class AnyMailer < ActionMailer::Base
# a delegation mailer class used to eval dynamic mail action
end
Then eval this class with defining an arbitrary method to perform the email sending.
def send_email(connection, files)
AnyMailer.class_eval do
def any_mailer(connection, files)
files.each do |file|
report_file_name = :foo
file_location = :bar
attachments[report_file_name] = File.open(file_location, 'rb'){|f| f.read}
end
mail(to: connection['to'], from: connection['from'], subject: 'Sample File', body: "<p>Hello,</p><p>Your data is ready</p>")
end
end
AnyMailer.any_mailer(connection, files).deliver_now
end
Attention, you don't need to specify the content_type as 'multipart/mixed', ActionMailer will handle it correctly. I tried to specify it explicitly but get messed up email content instead.
This has been driving me insane.
Make sure you have a well formed .html template and a .text template if you are using mailer views.
Minimal errors in either of them will render the entire email as a noname attachment.
You might don't have mailer.text.erb file along with mailer.html.erb file.
Add it and your mail will be multipart.

How do you send HTML content with SendGrid?

Trying to send HTML content in a SendGrid email header. I am getting drop email. The error is "REASON: Invalid SMTPAPI header"
This is my email template code
<%body%>
--|ALERT_MESSAGE|--
Here is the content I want to send (ROR string)
content = "<p>The system following info. [#{message}] <a href='#{url}'>#{url}</a></p>"
Here is my header code (self in this case is the header)
self.add_category("System Email")
self.add_filter('templates', 'enable', 1)
self.add_filter('templates', 'template_id', 'sdfs-f8fd6029')
self.add_substitution('--|MESSAGE|--', [content])
self.set_tos(SENDGRID_EMAILS)
Even if you are using a template, you need to specify some kind of body in the actual message, so that means you need to pass the html parameter i your request. This is an artifact due to transactional templates being added to the existing endpoint. A new mail sending endpoint is in the works that will not require text or html to be defined if a template is used.

Resources