Jenkins not sending email "Got bad greeting from SMTP host" - email

I am trying to send an email from a Jenkins pipeline but I am getting the following error
Adding recipients from trigger recipient list
Successfully created MimeMessage
Sending email to: 1211732#isep.ipp.pt
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: protocolConnect returning false, host=smtp.gmail.com, user=p-bri, password=<null>
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
DEBUG SMTP: EOF: [EOF]
DEBUG SMTP: got bad greeting from host "smtp.gmail.com", port: 465, response: [EOF]
MessagingException message: Got bad greeting from SMTP host: smtp.gmail.com, port: 465, response: [EOF]
I configured the SMTP with the following configurations
This is how I am sending the email
stage('Send confirmation email') {
emailext(
subject: "Pipeline notify - BUILD: '${env.JOB_NAME}#${env.BUILD_NUMBER}'",
body: """The pipeline runned successfully. The following tasks have been made:
- Project built
-Javadoc generation and publish
-Runned integration and mutation tests and published its respective reports
-Deployed the project to Tomcat, running at http://localhost:8888
Build can be found at: ${env.BUILD_URL}""",
recipientProviders: [[$class: 'DevelopersRecipientProvider']],
to: "1211732#isep.ipp.pt"
)
}

Try the following settings. This has worked for me.

Related

Swiftmailer email issue

I am sending email in Symfony2 using Swift Mailer.
//app/config.yml
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
port: "%mailer_port%"
encryption: "%mailer_encryption%"
spool: { type: memory }
And app/parameters.yml
mailer_transport: smtp
mailer_host: smtp.office365.com
mailer_user: notify#location.com
mailer_password: test
mailer_port: 587
mailer_encryption: tls
But I am getting following error again- and again.
app.ERROR: Exception occurred while flushing email queue: Expected response code 250 but got code "", with message "" [] []
How can I resolve this?
"SMTP error 554 is one of the more vague error codes, but is typically caused by the receiving server seeing something in the From or To headers that it doesn't like. This can be caused by a spam trap identifying your machine as a relay, or as a machine not trusted to send mail from your domain." - STMP error 554

Send ics file RSVP format not working properly using Outlook smtp server?

I have a code that works well when using gmail smtp server with my personal credentials :
fun sendEventInvitation(from: Profile, to: Profile, meetup: Meetup) {
val message: MimeMessage = emailSender.createMimeMessage()
message.setFrom(InternetAddress("foo1#foo1.com"))
message.setRecipient(Message.RecipientType.TO, InternetAddress("foo2#foo2.com"))
message.subject = "foo"
val messageBodyEvent = MimeBodyPart()
val id = UUID.randomUUID().toString()
val eventIcs = formatCalendarFile(id, from, to, meetup)
messageBodyEvent.dataHandler = DataHandler(ByteArrayDataSource(eventIcs, "text/calendar; charset=\"utf-8\"; method=REQUEST"))
messageBodyEvent.setHeader("Content-Transfer-Encoding", "base64")
val multiPart = MimeMultipart()
multiPart.addBodyPart(messageBodyEvent)
message.setContent(multiPart)
emailSender.send(message)
}
eventIcs is basically a String of an iCal correct format.
But whenever I switch to the outlook server using company's credentials, It gives the following error :
554 5.2.0 STOREDRV.Submission.Exception:InvalidRecipientsException; Failed to process message due to a permanent exception with message A message can't be sent because it contains no recipients. InvalidRecipientsException: A message can't be sent because it contains no recipients. [Hostname=AM6PR01MB5011.eurprd01.prod.exchangelabs.com]
DEBUG SMTP: got response code 554, with response: 554 5.2.0 STOREDRV.Submission.Exception:InvalidRecipientsException; Failed to process message due to a permanent exception with message A message can't be sent because it contains no recipients. InvalidRecipientsException: A message can't be sent because it contains no recipients. [Hostname=AM6PR01MB5011.eurprd01.prod.exchangelabs.com]
Now, weirdly enough, when I remove the method=REQUEST attachment header :
messageBodyEvent.dataHandler = DataHandler(ByteArrayDataSource(eventIcs, "text/calendar; charset=\"utf-8\"))
It works but because there's not this header, the ICS isn't well recognized by Outlook client and doesn't display RSVP options to the recipients as explained here.
I tried to send an invitation from Thunderbird using the same credentials and it works. So it's not link to rules whatsoever.
Here is the complete debug output :
DEBUG: JavaMail version 1.6.1
DEBUG: URL jar:file:/Users/baptistearnaud/.m2/repository/com/amazonaws/aws-java-sdk-ses/1.11.373/aws-java-sdk-ses-1.11.373.jar!/META-INF/javamail.providers
DEBUG: successfully loaded resource: jar:file:/Users/baptistearnaud/.m2/repository/com/amazonaws/aws-java-sdk-ses/1.11.373/aws-java-sdk-ses-1.11.373.jar!/META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], com.amazonaws.services.simpleemail.AWSJavaMailTransport=javax.mail.Provider[TRANSPORT,aws,com.amazonaws.services.simpleemail.AWSJavaMailTransport,Amazon Web Services LLC]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], aws=javax.mail.Provider[TRANSPORT,aws,com.amazonaws.services.simpleemail.AWSJavaMailTransport,Amazon Web Services LLC]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.office365.com", port 587, isSSL false
220 LO2P265CA0439.outlook.office365.com Microsoft ESMTP MAIL Service ready at Wed, 21 Nov 2018 11:01:22 +0000
DEBUG SMTP: connected to host "smtp.office365.com", port: 587
EHLO mbp-de-baptiste.lan
250-LO2P265CA0439.outlook.office365.com Hello [89.227.204.114]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "157286400"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
STARTTLS
220 2.0.0 SMTP server ready
EHLO mbp-de-baptiste.lan
250-LO2P265CA0439.outlook.office365.com Hello [89.227.204.114]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-AUTH LOGIN XOAUTH2
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "157286400"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN XOAUTH2"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: protocolConnect login, host=smtp.office365.com, user=SVC_ToGazer#uccint.onmicrosoft.com, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<foo1#foo1.com>
250 2.1.0 Sender OK
RCPT TO:<foo2#foo2.com>
250 2.1.5 Recipient OK
DEBUG SMTP: Verified Addresses
DEBUG SMTP: foo2#foo2.com
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Date: Wed, 21 Nov 2018 11:00:41 +0000 (UTC)
From: foo1#foo1.com
To: foo2#foo2.com
Message-ID: <681000169.0.1542798041668#mbp-de-baptiste.lan>
Subject: FOO
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_1_1921144901.1542798041673"
------=_Part_1_1921144901.1542798041673
Content-Type: text/calendar; charset="utf-8"; method=REQUEST
Content-Transfer-Encoding: base64
QkVHSU46VkNBTEVOREFSClZFUlNJT046Mi4wClBST0RJRDotLy9HUlRnYXogQ29ycG9yYXRpb24v
L05PTlNHTUwgVG9nYXonZXIvL0ZSCk1FVEhPRDpSRVFVRVNUCkJFR0lOOlZFVkVOVApVSUQ6YTQ5
ODVkZjUtNzI1YS00NTA0LTgzNWYtZDhkNTU2ZjliMDIzQHRvZ2F6ZXIuY29tCkRUU1RBTVA6MjAx
ODExMjlUMTgwMDAwWgpPUkdBTklaRVI7Q049dG9nYXplckBpbnQuZ3J0Z2F6LmV1Om1haWx0bzp0
b2dhemVyQGludC5ncnRnYXouZXUKQVRURU5ERUU7Q1VUWVBFPUlORElWSURVQUw7Uk9MRT1SRVEt
UEFSVElDSVBBTlQ7ClBBUlRTVEFUPU5FRURTLUFDVElPTjtSU1ZQPVRSVUU7Q049QmFwdGlzdGUg
QXJuYXVkOwpYLU5VTS1HVUVTVFM9MDptYWlsdG86YmFwdF9pczJAaG90bWFpbC5jb20KRFRTVEFS
VDoyMDE4MTEyOVQxODAwMDAKRFRFTkQ6MjAxODExMjlUMjIwMDAwClNVTU1BUlk6QWZ0ZXJ3b3Jr
IGdheidwYWNobwpMT0NBVElPTjpQYXJpcyA4ZSBhcnIKREVTQ1JJUFRJT046QWZ0ZXJ3b3JrIG/D
uSBsJ29uIHZhIGTDqWd1c3RlciBkdSBib24gZ2FzcGFjaG8uIEonZXNww6hyZSBxdWUgbGUgamV1
IGRlIG1vdCB2b3VzIHBsYcOudC4uLiBFeGNlbGxlbnQhCkVORDpWRVZFTlQKRU5EOlZDQUxFTkRB
Ugo=
------=_Part_1_1921144901.1542798041673--
.
554 5.2.0 STOREDRV.Submission.Exception:InvalidRecipientsException; Failed to process message due to a permanent exception with message A message can't be sent because it contains no recipients. InvalidRecipientsException: A message can't be sent because it contains no recipients. [Hostname=AM6PR01MB5011.eurprd01.prod.exchangelabs.com]
DEBUG SMTP: got response code 554, with response: 554 5.2.0 STOREDRV.Submission.Exception:InvalidRecipientsException; Failed to process message due to a permanent exception with message A message can't be sent because it contains no recipients. InvalidRecipientsException: A message can't be sent because it contains no recipients. [Hostname=AM6PR01MB5011.eurprd01.prod.exchangelabs.com]
RSET
250 2.0.0 Resetting
DEBUG SMTP: MessagingException while sending, THROW:
com.sun.mail.smtp.SMTPSendFailedException: 554 5.2.0 STOREDRV.Submission.Exception:InvalidRecipientsException; Failed to process message due to a permanent exception with message A message can't be sent because it contains no recipients. InvalidRecipientsException: A message can't be sent because it contains no recipients. [Hostname=AM6PR01MB5011.eurprd01.prod.exchangelabs.com]
Any ideas why there is this behavior ?
As mentioned #Bill Shannon in the comment section, the problem came from the calendar formatting.
You need to make sure your ics pass this kind of validator.
For example, in my implementation :
"""BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//GRTgaz Corporation//NONSGML Togaz'er//FR
METHOD:REQUEST
BEGIN:VEVENT
UID:$id
ORGANIZER;RSVP=FALSE;PARTSTAT=ACCEPTED;
ROLE=CHAIR:mailto:SVC_ToGazer#uccint.onmicrosoft.com
ATTENDEE;RSVP=FALSE;PARTSTAT=ACCEPTED;
ROLE=REQ-PARTICIPANT:mailto:${to.email}
DTSTAMP:${startDate[0]}T${startDate[1]}Z
DTSTART:${startDate[0]}T${startDate[1]}
DTEND:${endDate[0]}T${endDate[1]}
SUMMARY:${meetup.name}
LOCATION:${meetup.address}
DESCRIPTION:${meetup.description}
END:VEVENT
END:VCALENDAR
"""
The ORGANIZER and ATTENDEE props weren't valid. the property ROLE must be in the same line. So I modified it to:
"""BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//GRTgaz Corporation//NONSGML Togaz'er//FR
METHOD:REQUEST
BEGIN:VEVENT
UID:$id
ORGANIZER;RSVP=FALSE;PARTSTAT=ACCEPTED;ROLE=CHAIR
:mailto:SVC_ToGazer#uccint.onmicrosoft.com
ATTENDEE;RSVP=FALSE;PARTSTAT=ACCEPTED;ROLE=REQ-PARTICIPANT
:mailto:${to.email}
DTSTAMP:${startDate[0]}T${startDate[1]}Z
DTSTART:${startDate[0]}T${startDate[1]}
DTEND:${endDate[0]}T${endDate[1]}
SUMMARY:${meetup.name}
LOCATION:${meetup.address}
DESCRIPTION:${meetup.description}
END:VEVENT
END:VCALENDAR
"""
Now, it works properly.
As mentioned before, there are several types of online validators that can check if the format is valid. These two validators detect different types of errors.
http://ical-validator.herokuapp.com/validate/
https://icalendar.org/validator.html#results
For example, one of the things the validators will notice is that, whenever you use text, you have to escape the following characters:
\ ; , \n
Some things the validators treat as warnings (no CRLF line breaks, too much characters in the same line) can be ignored.
There are some errors that the validators won't be able to detect. For example, I got this SMTP error when the organizer's email was equal to the recipient's email. Finding it was non-obvious but I finally detected the source of the problem.
ORGANIZER;CN=Example:mailto:sameEmailAsTheRecipient#example.com
I hope Outlook can improve the feedback / error messages for iCal validation!

Jhipster - Configuring Email with Zoho - Error 553 Relaying disallowed

I am new to Jhipster and trying to configure zoho and I am getting errors.
My setting in /myjhipsterapplicationname/src/main/resources/config/application-dev.yml
mail:
host: smtp.zoho.com
port: 587
username: ****#myCustomDomainOnZoho.com
password: ****** // My password for the above email
protocol: smtp
tls: true
properties.mail.smtp:
auth: true
starttls.enable: true
ssl.trust: smtp.zoho.com
Errors, I am receiving
2017-03-02 21:15:13.421 WARN 6192 --- [ints-Executor-2] com.nectotech.com.service.MailService : E-mail could not be sent to user 'asif#nectotech.com'
org.springframework.mail.MailSendException: Failed to close server connection after message failures; nested exception is javax.mail.MessagingException: Can't send command to SMTP host;
nested exception is:
java.net.SocketException: Connection closed by remote host. Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 553 Relaying disallowed as breakpoints#localhost
I tried the following and it worked.
Go to /myjhipsterapplicationname/src/main/resources/config/application-dev.yml
Search for
mail: # specific JHipster mail property, for standard properties see MailProperties
from:
Replace the value of property from: with your SMTP outgoing email address

Grails mail plugin issues with Gmail SMTP

I'm using the grails mail plugin (2.0.0.RC2) with Grails 3.0.7. This is my config:
mail:
host: smtp.gmail.com
port: 465
username: myuser#gmail.com
password: myPassword
props:
- mail.debug: true
- mail.smtp.auth: true
- mail.smtp.socketFactory.port: 465
- mail.smtp.socketFactory.class: javax.net.ssl.SSLSocketFactory
- mail.smtp.socketFactory.fallback: false
When I try to send a test mail, I get the following error:
Caused by: org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
at grails.plugins.mail.MailMessageBuilder.sendMessage(MailMessageBuilder.groovy:131) ~[mail-2.0.0.RC2.jar:na]
at grails.plugins.mail.MailService.sendMail(MailService.groovy:55) ~[mail-2.0.0.RC2.jar:na]
at grails.plugins.mail.MailService.sendMail(MailService.groovy:59) ~[mail-2.0.0.RC2.jar:na]
at com.eduspace.ClassroomController.$tt__index(ClassroomController.groovy:13) ~[main/:na]
at grails.transaction.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:93) ~[grails-core-3.0.7.jar:3.0.7]
at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:90) ~[grails-core-3.0.7.jar:3.0.7]
... 9 common frames omitted
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1972) ~[javax.mail-1.5.1.jar:1.5.1]
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:656) ~[javax.mail-1.5.1.jar:1.5.1]
at javax.mail.Service.connect(Service.java:345) ~[javax.mail-api-1.5.1.jar:1.5.1]
... 15 common frames omitted
I see no other debug information in the logs. I have the root logger set to INFO, so everything should be getting outputted. I've verified that I can telnet to smtp.gmail.com port 465, so that's not the issue. I've read that others have had issues with SSL, but then there's usually some debug information indicating an SSL issue and I don't get anything like that.
I am using a slightly different config that works fine:
grails:
mail:
host: "smtp.gmail.com"
port: 465
username: "<username>#gmail.com"
password: "<password>"
props:
mail.smtp.auth: "true"
mail.smtp.socketFactory.port: "465"
mail.smtp.socketFactory.class: "javax.net.ssl.SSLSocketFactory"
mail.smtp.socketFactory.fallback: "false"
The mail config is inside in the grails placeholder and i am not using the dashes as in your example. Maybe this could be of help to you.
This could ofcourse be wrong due to config error but one of the reason for this exact error message is gmail configuration. To avoid spam messages, gmail has started blocking access from apps that do not conform to latest security guidelines.
One easy way to avoid this error is to go to your gmail account and allow less secure apps.- https://www.google.com/settings/security/lesssecureapps
Your configuration looks good.
Here is the mine working fine:
grails {
mail {
host = "smtp.gmail.com"
'default' {
from = "<username>#gmail.com"
}
port = 465
username = "<username>#gmail.com"
password = "<password>"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}

Jenkins fails on sending emails

I'm trying to send email from Jenkins using Extended Jenkins Email plugin.
Here is the output of the job:
Performing post-build step
Checking if email needs to be generated
Email was triggered for: Always
Email was triggered for: Always
Sending email for trigger: Always
messageContentType = text/plain; charset=UTF-8
Adding recipients from project recipient list
Adding recipients from trigger recipient list
Setting In-Reply-To since last build was not successful
Successfully created MimeMessage
Sending email to: tomasz.szandala#nokia.com
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "webmail-apac.nsn-intra.net", port 465, isSSL false
MessagingException message: Could not connect to SMTP host: webmail-apac.nsn-intra.net, port: 465
Sending email for trigger: Always
messageContentType = text/plain; charset=UTF-8
Adding recipients from project recipient list
Adding recipients from trigger recipient list
Setting In-Reply-To since last build was not successful
No, the question: how can I check wht is the problem?
I see only:
MessagingException message:
"Could not connect to SMTP host: webmail-apac.nsn-intra.net, port: 465"
How can I investigate the reason?
I think it's a network issue, your Jenkins server is not able to reach your SMTP server on the port 465.
Can you launch the following command to check if the port is open? (on your Jenkins server, with the jenkins account running the Jenkins app)
telnet webmail-apac.nsn-intra.net 465
If the port is open, you should see this response:
➜ ~ webmail-apac.nsn-intra.net 465
Trying XXX.XXX.XXX.XXX...
Connected to webmail-apac.nsn-intra.net.
Escape character is '^]'.
If the port is not open, try to disable the firewall on your Jenkins server.