Jenkins - sending email after build fails with multiple recipients - email

Brand new to Jenkins so forgive any noob errors. I have a Pipeline with this code:
pipeline {
agent any
stages {
stage('Ok') {
steps {
echo "Ok"
}
}
}
post {
always {
emailext (
subject:'Jenkins Build Test for XUSDK',
mimeType: 'text/html',
to: 'testuser#example.com',
recipientProviders: [[$class: 'DevelopersRecipientProvider'],[$class: 'RequesterRecipientProvider']],
body: 'Testing Jenkins sending an email message after building a job.'
)
}
}
}
This works fine and sends an email to the recipient in the to field. However, if I change that value to:
to:'testuser'#example.com','testuser2#example.com',
The build fails and I receive this error:
WorkflowScript: 14: Arguments to "emailext" must be explicitly named. # line 14, column 11.
emailext (
My Google-fu failed and I was not able to find a solution. Checking SO, other answers have indicated this is the proper way to send email to more than one recipient. Any help would be appreciated.

Use the below:-
to:'testuser#example.com,testuser2#example.com'

Related

Jenkins emailext not sending mails

I am currently trying to understand why Jenkins is not sending emails.
The expected behavior is, that Jenkins will send emails to the whole team if the master branch is broken. If a feature branch breaks a email to the person who broke it, should be send.
Emails for the master branch are working, but not for broken feature branches.We are using the email-ext plugin. If you take a look at the code below you will see that the getEMailRecipients function will return an empty string for feature branches.
Docs example
In the docs an example is given that should
Send an email to abc plus any addresses returned by the providers
emailext (
body: 'A Test EMail',
recipientProviders: [
[$class: 'DevelopersRecipientProvider'],
[$class: 'RequesterRecipientProvider']
],
subject: 'Test',
to: 'abc'
)
My understanding of this example is, that an email should be send even if the to property is empty.
Property value docs
The docs for the plugin state the following for the 'CulpritsRecipientProvider' option
Sends email to the list of users who committed a change since the last
non-broken build till now. This list at least always include people
who made changes in this build, but if the previous build was a
failure it also includes the culprit list from there.
My Code
Helper functions:
def getTeamRecipients() {
return 'name1 name2 nameX'
}
def getEMailRecipients(currentBranch) {
return (currentBranch.toLowerCase().contains("current") ||
currentBranch.toLowerCase().contains("master")) ?
getTeamRecipients() :
""
}
def sendEMail(recipients) {
emailext (
to: recipients,
subject: "Job '${env.JOB_NAME}' is in state ${currentBuild.currentResult}",
body: "See ${env.BUILD_URL} for more details",
recipientProviders: [
[$class: 'CulpritsRecipientProvider'],
]
)
}
Email Send part:
if (currentBuild.currentResult == "FAILURE") {
def recipients = getEMailRecipients("$BRANCH_NAME")
sendEMail(recipients)
}
Does anyone have an idea what is wrong with my build script code?

Python 3.4 email to multiple receivers throws an ERROR

I'm writing a script to send an email to more than one email account, but not able, yet.
It works as it is below, but if I set receivers='xxx#xxx.com','yyy#yyy.com' it won't work, it throws an error:
AttributeError: 'tuple' object has no attribute 'encode'.
How can I set receivers=?
def send_email (out_file):
sender = 'xxx#xxx.com'
receivers = 'xxx#xxx.com'
email_pass = 'aaaa'
filematch=re.findall('NE.*\.txt',out_file.name)
subject = ("NEXXXX_price_update")
message = ("The following file was forwarded to your ftp account %s " %filematch)
msg = 'Subject: %s\n%s' %(subject, message)
try:
smtpObj = smtplib.SMTP_SSL('smtp.gmail.com',0)
smtpObj.login(receivers, email_pass)
smtpObj.sendmail(sender, receivers, msg)
print ("Successfully sent email")
except SMTPException:
print ("email NOT successful")
print(SMTPException.__cause__)
smtpObj.quit()
You assign wrongly
receivers='xxx#xxx.com','yyy#yyy.com'
You suppose to assign as a tuple or list, not sure 100% which.
Give a try:
receivers=('xxx#xxx.com','yyy#yyy.com')
or
receivers=['xxx#xxx.com','yyy#yyy.com']

Sending email with large body is failing

When sending an email from C# with body being large is resulting in failure in sending email
Mailbox unavailable.
The email is working fine with a smaller body. I am using html body to true property..
Thanks,
Zafar
Code:
using (MailMessage _mailMsg = new MailMessage())
{
_mailMsg.From = new MailAddress(ConfigurationManager.AppSettings["mailFrom"].ToString());
_mailMsg.Body = mail.Body;
_mailMsg.Subject = mail.Subject;
_mailMsg.IsBodyHtml = true;
foreach (string strEmailIds in mailTo)
{
if (strEmailIds != null && strEmailIds != string.Empty && strEmailIds != "")
{
if (!_mailMsg.To.Contains(new MailAddress(strEmailIds)))
_mailMsg.To.Add(new MailAddress(strEmailIds));
}
}
//_mailMsg.CC.Add(ConfigurationManager.AppSettings["mailCC"].ToString());
using (SmtpClient _client = new SmtpClient(ConfigurationManager.AppSettings["Host"].ToString()))
{
if (_mailMsg.To.Count > 0)
{
_client.Send(_mailMsg);
}
else
{
_mailMsg.Subject = "No emails associated with the portfolio: " + account + " Original Email:" + mail.Subject;
_mailMsg.To.Add(new MailAddress(ConfigurationManager.AppSettings["mailSuppotTeam"].ToString()));
_client.Send(_mailMsg);
}
Oke, on thing it could be is that the mail server rejects big messages. Let exclude that one... I assume you have a local smtp mail server installed (check for telnet 127.0.0.1 25 that should give a sort of reply) configure the mail server [ConfigurationManager.AppSettings["Host"]] for 127.0.0.1, can you send big mails now?
If ConfigurationManager.AppSettings["Host"] is already the local SMTP server then:
a) stop that smtp service (Simple Mail Transfer Protocol) for a moment (via the command services.msc)
b) send a small email
c) go to c:\inetpub\mailroot\pickup and edit the message via notepad so that it becomes a BIG email
d) start the smtp service again (services.msc)
The issue was with sending email to cross domain email id and was resulting in the Generic exception
"Mailbox unavailable." May be this is one of the reason behind the above exception.

Sending emails from Hyperion server

I am trying to send emails from hyperion servers when the number of records is 0.I am writing the script code in onPostProcess().
var dtm_current = new Date();
Application.ExecuteBScript("Set BrioQuery, Mail, 'Internet Mail', mailserverwithoutquotes,fromid'"); //note that mailserver name is given without quotes and
//from id does nt have starting quote
Application.ExecuteBScript("Export Section Root.'Results', OfficeMHTML, 'job_output', Silent, email, 'Testing Email action', 'This is a test of the email action. \n\n\n', UTF-8, To, tomailid'");
Console.Writeln ( "Post Process Script complete:"+dtm_current );
I am getting the error
Emailing section 'Results' as 'Microsoft Office Web Archive' to:
com'
Export failed. Error: Connection failed to locate host, 127.0.0.1. Is the SMTP server on port 25? (Errcode=146)
Question I have : Why it is trying to connect to localhost instead of specified email server
I have got this working.
var dtm_current = new Date();
Application.ExecuteBScript("Set BrioQuery, Mail, 'Internet Mail', emailserverwithoutquotes,'fromemailid'");
var count =1* ActiveDocument.Sections['R-Results'].RowCount;
Console.Writeln(count);
if(count > 0){
Application.ExecuteBScript("Export Section Root.'R-Results', csv, 'job_output', Silent, email, 'Testing Email action if', 'This is a test of the email action if. \n\n\n', UTF-8, To, 'tomailid'");
}
else{
Application.ExecuteBScript("Export Section Root.'R-Results', csv, 'job_output', Silent, email, 'Testing Email action else', 'This is a test of the email action else. \n\n\n', UTF-8, To, 'tomailid'");
}

Send email codeigniter function returns "Recipient address rejected: Domain not found" instead of false

I'm using codeigniter. I test to send an email to a wrong inexistant address like t#t.com.
My code is just a method of the controleur like that :
function test() {
$this->email->from('mymail#gmail.com');
$this->email->to(htmlentities("t#t.com"));
$this->email->subject('test');
$this->email->message("Just a test !");
$r = $this->email->send();
if (!$r)
echo "not sent, wrong email";
else
echo "sent";
}
Basically, the send() function returns true or false. But it doesn't work ! The error message I got is as following :
A PHP Error was encountered
Severity: Warning
Message: mail() [function.mail]: SMTP server response: 550 5.1.2 <t#t.com>: Recipient address rejected: Domain not found
Filename: libraries/Email.php
Line Number: 1540
not sent, wrong email
I have the message, so send() function replies false but I also have the error message, which I don't want !
It's a blocking point. Anyone has an idea why send() function doesn't return the true or false reply ?
thanks by advance !
a quick and dirty hack to get rid of the error is to prepend the mail function with '#':
$r = #$this->email->send();
I've tried it and it works as it should, I get: not sent, wrong email.
What version of CI are you using? make sure it's the last one.
Just in case, check the Email.php library under system/libraries in your CI folder
protected function _send_with_mail()
{
if ($this->_safe_mode == TRUE)
{
if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str))
{
return FALSE;
}
else
{
return TRUE;
}
}
else
{
// most documentation of sendmail using the "-f" flag lacks a space after it, however
// we've encountered servers that seem to require it to be in place.
if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From'])))
{
return FALSE;
}
else
{
return TRUE;
}
}
}
Check that the function _send_with_mail() inside looks exactly like the one above