Accessing GMail with GMail client and JavaMail (via pop3) - gmail

I've written a JavaMail client to access a GMail account via POP3.
As expected, I can only read a message once. When I re-run the client, the message is not found as it has been deleted from the server.
However, when I then log onto the GMail account (IMAP enabled) via a browser, the message appears.
Why does this happen? Are separate copies of the email created for POP3 and IMAP?

POP3 clients access the inbox, and what they see is unseen mail. When the POP3 client has seen a message it's no longer unseen and the POP3 server is supposed to do something.
The gmail server probably moves the message to the Archived folder.
You may have won a prize as the last person to have written a POP3 client, BTW.

Gmail has specific special handling for POP3 account:
In the default mode, it expects a 'download and delete' client. It will only expose 300 or so messages until those are DELEted. They are not actually deleted, but they are removed from the pool of messages to be sent through POP3. This prevents some of the inefficiencies with traditional POP3 clients accessing huge mailboxes, but does allow the client to eventually access everything.
The other mode is recent mode. You can use this mode by putting "recent:" in front of your login, like "recent:bob#gmail.com". This switches it to a mode where it will only show your client the most recent 30 days worth of messages. The messages do not disappear, until they fall out of the window. Again, this limits the size of the message list to a reasonable number for efficiency reasons, but in a different way. However, deletes can be synced between clients. (This may mean archiving in the Google Way). Recent mode is currently documented here in the troubleshooting section I want to download emails on multiple email clients.
Or, you could just use IMAP. Even without using all the additional features of IMAP, you can do everything you can do with POP3, but will allow many other features as your client evolves.

Related

can I send an email through a PHP mailer with my localhost without Gmail?

can I send an email through a PHP mailer with my localhost without using Gmail? or any other email service like Hotmail, outlook using my localhost?
Yes, and this is actually the best way to send using PHPMailer. There are two things you need:
A hosting provider that permits outbound SMTP. A large number of providers block SMTP by default, but you may find that they will remove the block on request (scaleway.com), provide an alternative service (AWS), which may also be acceptable.
A locally installed mail server. If you're on Linux, something like postfix is a good choice.
The way it then works is this:
Write your PHPMailer script as normal, but delivering to localhost over SMTP (not via mail())
Configure your mail server to act as a "full" mail server, where it attempts to deliver messages directly, or to act as a "smarthost" to relay through some other service, such as gmail or mailgun.
The main advantages of this approach are:
Perceived performance: your message submissions will appear to be instant, so it's great for things like contact forms
Reliability: if your message can't be delivered immediately, the local mail server will automatically take care of queuing and redelivery attempts, in a way that is far more efficient than you would ever achieve if you handled that within your own application.
As with many things, with great power comes great responsibility, and you will have to deal with bounce handling, blacklisting, inbound filtering (or just block it), etc. It's probably not worth doing all this for a simple contact form, but if you have an application that generates a reasonable amount of email traffic (signups, password resets, notifications, etc), it's a great way to go.

Synchronizing Gmail mail

I have fetched all Gmail mail using JavaMail API Imap protocol and show them in table format but now the problem is how show delete them?
on click that mail has to be deleted, all connection using protocol is lost and I want to delete that mail.
Once you lose the connection to the server, you're effectively operating in "disconnected" mode. The JavaMail FAQ has pointers to more information about how to handle disconnected mode with IMAP. Doing this well is a lot of work.
A simpler approach is to do your best to ensure the connection isn't lost unnecessarily, e.g., by calling Folder.getMessageCount at least every 30 minutes. If you still lose the connection (which will happen sometimes),
you toss all your cached data, reconnect, and refresh the user's view.
If you only care about being able to delete messages that the user can see, you might be able to take an intermediate approach. You could save the UID of all messages (and the UIDVALIDITY of the Folder) and when the connection is lost you would reconnect and get the Message objects for all messages based on UID. Then you would be able to delete the message, if it still exists on the server.

want to monitor new mails with different account imap credential

I'm implementing an Email Client Application to monitor new email arrival for different IMAP configuration simultaneously. I preferred Nodejs, but I stuck up with connection creation.
Let me explain with following example:
I have 3 IMAP configurations (it's not restricted to 3, each provider may have 10, 100, 1000 or > 1000 users).
Gmail
Yahoo!
Hotmail.
I did the configuration for these 3 providers. Now I want to monitor above 3 mail servers for different users. Let's say Gmail with 1000 different users, Yahoo! with other 1000 users and Hotmail with 1000 users.
My question is I want to monitor new email arrival for every user with every mailbox.
Will NodeJS be helpful to do this? It's going to create many TCP connections.
I want to implement this with less network cost.
Similar to this question:
Why can't I login to an imap server twice in Python
What you are expecting IMAP to do cannot be done. When you connect to
an IMAP server you issue a LOGIN, do some stuff, then eventually give
a LOGOUT. After the LOGOUT you cannot do another LOGIN.
So whatever IMAP library you use will have to generate a TCP socket
connection for each mailbox you check. With that said Node.js has
some pretty easy-to-use IMAP modules:
https://github.com/andris9/inbox - Easy checking of inboxes
https://github.com/mscdex/node-imap - More low-level IMAP stuff

IIS SMTP Message Inspection

Is there a way to peek or see a message before it hits the SMTP on IIS. This is not an Exchange Server, it's just running SMTP. I am trying to see if I can look at the message and then pass it to SMTP?
Thanks
Edit ~ Instead of adding another listner, I am wondering if there is a way to bind to the default SMTP listner and intercept the message then pass it on.
2nd Edit~ Ok, here is my problem. I have a spam filter in front of my exchange box, unfortunately (due to software design) the filter is limited when it comes to "Directory Harvesting Loookup". This is the process where the email addresses are checked if they exists in AD and the mail is dropped if they don't. My current filter drops the mail if one of the addresses does not exists in AD which is not good. I spoke with the vendor and there is nothing they can do at this time. I am looking put an app in front of this filter which would intercept (open, read, parse) the mail, validate the addresses, and then pass on the email to the filter for additional scanning. I'll then trun off this feature in their software. Don't get me wrong, their filter works great with this one exception which I must fix since I have tons of emails send to nonexistent users in my domain.
You can write your own Proxy SMTP service that you connect to to send messages. You can forward all messages directly to your actual SMTP service and pass all responses back. Then you can evesdrop on all these messages and deal with them accordingly.
Might be a bit overkill for what you're after but it's fairly simple to code as you dont need to know anything about the protocol as all you're being is a proxy.
If you're using .NET 2.0 then you can log SMTP sessions to a file:
How do I create a log file of the SMTP session? (System.Net.Mail)
Updated:
Take a look at this question:
Testing SMTP with .net (Stack Overflow)
From your edit:
"I am wondering if there is a way to bind to the default SMTP listener and intercept the message then pass it on?"
...and from your comment below:
"I am looking to inspect the actual message before the SMTP gets it."
I'm not sure if you fully understand the SMTP protocol. SMTP messages aren't just monolithic fire-and-forget entities. SMTP is session based and there is a conversation between client and server, of which, the message is just a part. The tracing method (linked to above) will record the entire exchange between client and server and does intercept the whole message before passing it on. The alternative, a proxy or mock server, will still require your application to engage in the SMTP client/server exchange. The closest solution to your requirement would be to use something like Papercut which is linked to in the answer above.
Kev
In .Net you can tell the SmtpClient to send email to a different folder than the SMTP service is monitoring. That way you could check each message, then move it to the real pickup folder. (See SmtpClient.PickupDirectory)
IIRC, you can still write up event sinks for the IIS SMTP service (even though it's not full blown exchange). It's been many years since I've done this, but you may want to google for "exchange event sink" to see if that helps.
Seems like a something like Ethereal will let you accomplish the sniffing portion of your request. Its not clear to me what you mean by "intercept" and "pass on". Do you want to filter some traffic or just delay traffic long enough for you to inspect before you pass it on, or both?

How should I move queued messages from IIS to Exchange on different servers?

We currently have a company email server with Exchange, and a bulk email processing server that is using IIS SMTP. We are upgrading to a 3rd party MTA (zrinity xms) for bulk sending. I need to be able to keep sending the messages already queued for IIS when we switch to the 3rd party sofware. Can I simply move the IIS queue files to the Exchange server queue and have sending attempts begin automatically for them? If not, any suggestions on accomplishing this?
You should be able to move the *.eml files to the Exchange server's pickup directory. Or set the IIS SMTP service to smart host to the new MTA, assuming they (the 3rd party) allow SMTP relay from your IP address.
Moving the files will work. However, any email with a BCC line in the header will get sent out with the BCC intact. Some clients, such as gmail, will display the information to the recipient, thus breaking the whole point of BCC.
This happens when copying EML files to MS-SMTP (which Exchange also uses) because the BCC information is usually stripped out of the header in during the SMTP hand-off to (not from) MS-SMTP.
If that was how the messages were initially handed off, then it's possible that the EMLs you have were already broken into separate messages for each BCC, and that header was properly stripped.
Just a little gotcha to watch out for.

Resources