MailKit: The IMAP server replied to the 'EXAMINE' command with a 'BAD' response - mailkit

I got this error on an Exchange 2007 mailbox. I see it is returning the BAD response from the error which is thrown by MailKit:
The IMAP server replied to the 'EXAMINE' command with a 'BAD' response.
But this doesn't tell me enough detail. So I am running protocol logging, from which I can tell what the problem is. It says:
K00000005 BAD Duplicate folders "Conversation Action Settings", "News Feed", "Quick Step Settings", "Suggested Contacts" were detected in the mailbox. Therefore the user's connection was disconnected.
I would like to get this error text and display it to the user, so they can fix their mailbox (which they can do by deleting the duplicate folders, assuming they know which ones they are). Is there a simple way to get the full response text?
Full protocol log as follows:
S: * OK Microsoft Exchange Server 2007 IMAP4 service ready
C: K00000000 CAPABILITY
S: * CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN IDLE NAMESPACE LITERAL+
S: K00000000 OK CAPABILITY completed.
C: K00000001 AUTHENTICATE NTLM
...
S: K00000001 OK AUTHENTICATE completed.
C: K00000002 CAPABILITY
S: * CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN IDLE NAMESPACE LITERAL+
S: K00000002 OK CAPABILITY completed.
C: K00000003 NAMESPACE
S: * NAMESPACE (("" "/")) NIL NIL
S: K00000003 OK NAMESPACE completed.
C: K00000004 LIST "" "INBOX"
S: * LIST (\Marked \HasNoChildren) "/" INBOX
S: K00000004 OK LIST completed.
C: K00000005 EXAMINE INBOX
S: K00000005 BAD Duplicate folders "Conversation Action Settings", "News Feed", "Quick Step Settings", "Suggested Contacts" were detected in the mailbox. Therefore the user's connection was disconnected.
S: * BYE Connection is closed. 15

You can try parsing the ImapCommandException.Message property to get the text following the ':' character that is used in the exception message.
I've also just added a ResponseText property to ImapCommandException so you can get this text w/o needing to parse it if you want to use MailKit built source.

Related

KeyCloak fails to send email using SMTP with status 500

I have Keycloak running in a Kubernetes cluster. Authentication works but I need to set up e-mail to be able to send e-mails for verification and password reset.
I have SendGrid set up as an SMTP Relay. These settings (host, port and api key) work when I send mail using the SendGrid java client. However, when pressing Test connection in KeyCloak I get:
[Error] Failed to load resource: the server responded with a status of 500 ()
[Debug] Remove message (services.js, line 14)
[Debug] Added message (services.js, line 15)
[Error] Can't find variable: error
https://<domain>/auth/resources/ong8v/admin/keycloak/js/controllers/realm.js:76 – "Possibly unhandled rejection: {}"
[Debug] Remove message (services.js, line 14)
There isn't much to go on here. I have an e-mail address set up for the currently logged in user. I've also tried resetting the password in case the Test connection functionality was broken but that didn't work either.
The Realm Settings settings user for email are as such:
host: smtp.sendgrid.net
port: 587
from: test#<domain>
Enable StartTLS: true
Username: "apikey"
Password: <api key>
Any idea what can be wrong? Or how to find out? For instance, maybe I can get a more meaningful error message somehow.
Edit:
I got the server logs.
Failed to send email: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.sendgrid.net, 587; timeout 10000;
nested exception is: java.net.SocketTimeoutException: connect timed out
Edit 2:
I've tried sending mail using Telnet using the exact same settings and that works. So apparently it's something with Keycloak or its underlying Java libraries that's causing issues sending e-mail.
Turns out that Keycloak works and that emails were blocked by the hosting provider.

mailkit imap Authenticate failed

Connected to imap://mail.xxxxx.com:143/?starttls=when-available
S: * OK The Microsoft Exchange IMAP4 service is ready.
C: A00000000 CAPABILITY
S: * CAPABILITY IMAP4 IMAP4rev1 LOGINDISABLED STARTTLS UIDPLUS CHILDREN IDLE NAMESPACE LITERAL+
S: A00000000 OK CAPABILITY completed.
C: A00000001 STARTTLS
S: A00000001 OK Begin TLS negotiation now.
C: A00000002 CAPABILITY
S: * CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN UIDPLUS CHILDREN IDLE NAMESPACE LITERAL+
S: A00000002 OK CAPABILITY completed.
C: A00000003 AUTHENTICATE NTLM
S: +
C: TlRMTVNTUAABAAAABwIIAAAAAAAgAAAAAAAAACAAAAA=
S: + TlRMTVNTUAACAAAACAAIADgAAAAFAokCQ1Oy6n0KV+wAAAAAAAAAAJAAkABAAAAABgGxHQAAAA9DAE8AUgBQAAIACABDAE8AUgBQAAEABABBAEQABAAeAGMAbwByAHAALgB3AG8AcwBpAGcAbgAuAGMAbwBtAAMAJABhAGQALgBjAG8AcgBwAC4AdwBvAHMAaQBnAG4ALgBjAG8AbQAFAB4AYwBvAHIAcAAuAHcAbwBzAGkAZwBuAC4AYwBvAG0ABwAIAEgKvfK4E9IBAAAAAA==
C: TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgAAAAAAAAABIAAAAIAAgAEgAAAAAAAAAaAAAAAAAAACYAAAAAYIIAgoAWikAAAAPYwBtAHMAMQA1AEAAdwBvAHMAaQBnAG4ALgBjAG8AbQBIi1QHDf/aHwAAAAAAAAAAAAAAAAAAAAClb/du5aSYbtWcPg24wC4ZDwe68ixMp2g=
S: A00000003 NO AUTHENTICATE failed.
C: A00000004 AUTHENTICATE PLAIN
S: +
C: XXXXXXXXXXXXX
S: A00000004 NO AUTHENTICATE failed.
C: A00000005 LOGIN xxxx xxxx
S: A00000005 NO LOGIN failed.
NTLM authentication does not work in the current release of MailKit 1.6.0 (well, it works with some servers, but apparently not others).
According to https://github.com/jstedfast/MailKit/issues/397, a patch that I recently committed will theoretically fix this issue but I have had no word back from the person who submitted the bug to confirm that it works.
You can either compile from source downloaded from GitHub or wait for the next release.
In the meantime, you could just disable NTLM authentication like so:
client.AuthenticationMechanisms.Remove ("NTLM");
Make this call just before calling Authenticate().

Unable to send email in Lemoon CMS?

The following error appears when trying to send email via LemoonCMS Test email page.
"Transaction failed. The server response was: 5.7.1 : Sender address rejected: Access denied"
The web.config settings is correct, as i uploaded a custom page using the same settings and its works fine.
The following error taken from the LOG:
2014-08-03 13:38:48.9950|INFO|Mindroute.Core.BootStrapper|Startup completed in 674ms
2014-08-03 13:38:49.2790|INFO|Mindroute.Core.Services.MailService|Sending mail 'Lemoon test message' to 'mfaris#kanzit.com'
2014-08-03 13:38:55.9600|INFO|Mindroute.Core.Services.MailService|Sending mail 'Lemoon test message' to 'mfaris#kanzit.com'
2014-08-03 13:39:09.1240|INFO|Mindroute.Core.BootStrapper|Shutting down. Reason: ConfigurationChange
2014-08-03 13:39:09.1290|INFO|Mindroute.Core.FullText.LuceneFullTextProvider|Disposing FullTextIndex
2014-08-03 13:39:09.1290|INFO|Mindroute.Core.BootStrapper|Shutdown completed in 6ms
Lemoon uses the settings from the MailDaemon when sending email. Have you checked that it is configured correctly? Otherwise it sounds from the error like the problem is with the mail server and not with Lemoon.

QuickFix/N sending repeated logons

I use QuickFixN to connect to 2 liquidity providers.
One is connecting and working fine. The other isn't showing any error message, seems to be connecting, but Logon isn't succeeding.
In the messages log: I am sending the Logon request (message type 'A'), and receiving back another message type A, but then nothing happens. 30secs later this happens again. It has many repeats looking like this:
20131118-20:11:32.422 : 8=FIX.4.49=11535=A34=149=XXXX50=XXXX52=20131118-20:11:32.40856=XXXX57=XXXX98=0108=30141=Y10=152
20131118-20:11:32.795 : 8=FIX.4.49=11535=A34=149=XXXX50=XXXX52=20131118-20:11:32.61956=XXXX57=XXXX98=0108=30141=Y10=156
....same again every 30secs....
the event log looks like this:
20131118-20:11:32.023 : Connecting to AA.AAA.AAA.AAA on port BBBB
20131118-20:11:32.395 : Connection succeeded
20131118-20:11:32.408 : Session reset: ResetOnLogon
20131118-20:11:32.422 : Session reset: ResetSeqNumFlag
20131118-20:11:32.422 : Initiated logon request
20131118-20:11:32.796 : Message 1 Rejected: 9
20131118-20:11:32.798 : Verify failed: Tried to send a reject while not logged on
20131118-20:11:32.798 : Session FIX.4.4:XXXX->YYYY disconnecting: Verify failed: Tried to send a reject while not logged on
Within my application, on the QuickFix.Application interface, OnCreate is being called for this session, and so is OnLogout, but OnLogon is not. Neither FromAdmin or FromApp receive any messages from this session.
What could I be doing wrong?
The "Message 1 Rejected: 9" phrase is saying the message with sequence number 1 (the Logon message) was rejected for reason 9. The reason is a FIX Session Reject Reason and 9 indicates a CompID problem. Double-check your sender and target CompIDs in the message to be sure they are correct for your counterparty. Note that your side of the session is rejecting their login so it could be an issue with configuration of your session. The "Verify failed" message is logged because QuickFIX/n is apparently trying to send a reject message before the session is logged in.

How do you fix 550 must be authenticated sending Mail using Grails?

I'm using Grails Mail plugin and trying to send email and keep getting:
Error 500: Executing action [sendInvite] of controller
[RegisterController] caused exception: Failed messages:
javax.mail.SendFailedException: Invalid Addresses; nested exception
is: com.sun.mail.smtp.SMTPAddressFailedException: 550 must be
authenticated
I'm properly following the instructions at: http://www.grails.org/Mail+plugin
The mail server is returning an error when you try to send out the mail. 550 is a generic SMTP failure code; in this case it looks like you are missing a username and password. Some SMTP servers to not require authentication but most do, especially if they're publicly available on the internet. It's also possible that your SMTP server requires an SSL connection and you're connecting with an unsecured socket.
The example config for gmail shows how to set all the mail server authentication options in Config.groovy:
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "youracount#gmail.com"
password = "yourpassword"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
Add "mail.debug": "true" to props to turn on JavaMail debugging to get a better picture of what is happening before the failure.
In my case the 550 error was caused by me having accidentally selected and IMAP account as the default account but sending emails from my Outlook Connector Account (which has no authentication settings to make).
I changed the Outlook Connector Account to default. Resent the emails and no errors.
So check that the correct email account is set up as the default also