I writing a mail client for sending of email notification using Javax.mail SMTP. I need to validate the mail delivery. my first step ofcourse was to catch built in exception.
My question does those exceptioon cover delivery errors (i.e. failed delivery becouse of wrong adrress, target server not found etc) or do I need to do extra work to cover that.
Thanks,
Alex
Once the email is successfully delivered to the destination server, it's gone. If that server is a relay (as you would typically find in a corporate environment) the message could bounce later when the relay tries to send it to the real destination.
At that poing, a bounce message would be returned to the sending address. If you need to handle those, you need to ensure that the sending address is deliverable to a mailbox to which you have access. Then you need to somehow (i.e. procmail) get the incoming bounces to another program you write which handles them.
Related
From a search, I can find a lot of similar questions to this but all of them seem as far as I can tell to have either been misunderstood or to not be quite the same as this question.
Presumably (maybe not but it seem unlikely) an email process/server knows which emails it holds a record of because they "arrived" and which it holds a record of because someone used SMTP or similar to tell the server to "send" an email out.
If a POP3 client retrieves lots of emails from the server and (we know from observation that) some of those emails are emails that the server was told to send out and some are emails it received, then is the pop3 server contravening the protocol because it provided for download, emails which were conceptually NOT in the "Inbox" or is it at liberty to send what ever it wants since POP3 has NO concept of folders and emails are emails.
Either way, is there an easy and robust way for the client to distinguish between these emails? Or is checking the from field against the account the best on offer? I believe pop3 messages support flags, some POP3 apis do, but perhaps servers are not obliged to make any guarantees, plus I don't see a very clear description of their meaning, so I don't if they can be consisently used to distinguish.
For implementation my preference is Java and com.sun.mail.pop3
I realize there is IMAP, but at this stage I'd like if possible to make a very small change to POP3 client implementation and look at switching to IMAP another time.
Thank you.
POP3 is a protocol to get the messages of your inbox. To send messages you use SMTP protocol.
In my understanding you contact the server using SMTP and deliver a message to the server. The server then delivers this mail to the corresponding target mail server and stores the message in that inbox.
On the other side you contact your own inbox using POP3 to receive the message that are stored in your inbox.
Thus there never should be any conflict between ingoing and outgoing emails as these are two different things and the servers supplying pop3 and smtp for your mailbox can be two total different servers on total different locations. Thus, within one mail server inbox and outbox should be two different storage locations.
"Conclusively distinguishing" depends on how/why the messages are being seen in POP3. A best effort type solution, though, would involve substring scanning the From field looking for what was provided in the USER command. If a token based authentication mechanism is being used, then you'll need to get an email identifier from whomever issued the token and look for that in From header.
As background, a basic concept in POP3 is called the "maildrop". Most people equate that to "Inbox" in IMAP terms, but it's not necessarily the same. For example, a message filtered at deposit time into a custom folder might show up in POP3's maildrop even though it doesn't show in Inbox via IMAP or Webmail. What goes into the maildrop and is therefore seen in POP3 can vary from implementation to implementation.
If a user only has POP3/SMTP and Webmail as their choices, they'll sometimes BCC themselves on sending to make sure a copy exists somewhere on the server so that they can access it via Webmail if needed. That's because very few SMTP implementations automatically save the message to the user's mailbox, and POP3 has no mechanism for saving the message anywhere but local to the user-agent. For those SMTP servers that do automatically save sent mail in the mailbox, they might just put it in the maildrop when it comes to POP3 servers.
I have used java mail(com.sun.mail.smtp) from my struts project. Mail is sent successfully but the receiver end the mail so delayed. It will take 2 or 3 hrs.
When am using PHP mailer with the same smtp settings , there is no delay, mail is working perfectly.
Anybody facing this issue, know what is the reason?
Javamail doesn't store and forward messages. So if you have have successfully sent the email to the mail server by calling Transport.sendMessage() and not receiving an error. It's sitting on the mail server waiting to be delivered. You'll need to check what you have set as your smtp server, user name, and password. Those are what you send to Transport.connect(server, username, password). Make sure they are the same as the ones you are using in PHP. If you aren't setting them in PHP then I bet you aren't using the same settings and hence why one server takes longer than the other.
Put some timing statements around the calls to Transport.connect(), Transport.sendMessage(), Transport.close(). See how long its taking to make it through that section. If its taking really short time then you know the error exists on the mail server side. And I bet you aren't talking to the server you think you are talking to.
I'd like to write a program, probably a servlet or something to run on the a google app engine that I can send an email to. So not a program to send email, but one that can receieve it and parse it.
My question is, what code or API are out there that can receive an email?
Basically on your google app engine you can use an inbound mail service.
Please see this documentation for more information.
http://code.google.com/appengine/docs/java/mail/overview.html#Receiving_Mail_in_Java
You cant send an email to a program, you send an email to a server, so what you are looking for is a way to access an email server via your program. Unfortunately there is no single solution here, you need to configure your program for every different email account/server you want to access. (If you have ever set up an account in outlook or something like it you will get the idea)
For example here is a link to the gmail api, you could use this to access gmail accounts
http://code.google.com/apis/gmail/
You need to have a mailbox to send message there and you could read messages with the code like this: http://www.java2s.com/Code/Java/Network-Protocol/GetEmailMessageExample.htm
This can be done with a built in Java library.
javax.mail
Check out this link. It should be able to help you get started.
This won't work for every mail server, but depending on your setup it might help.
To send an email to a Java program, that program must be running. Generally that means a server style (aka service) receiver is favored.
For the email to be received, the Java service must understand an email protocol. There are a number of protocols, but SMTP is the standard for receiving email. Once you have a service that understands SMTP protocol for receiving email, you have written a mail server.
Note that most people don't care to write a mail server, as a mail client needs to connect to the server and pull the email to make it readable. Keep this in mind when designing the solution to your problem.
I'm using Java to send messages from Gmail with Apache Commons Email, but it seems like it doesn't allow me to send messages from an address different from the one that I use to authenticate.
How do you send messages from a different address using Gmail and Java?
Basically, you are looking for an SMTP server which will let you send a message by spoofing the From MIME header. Well, if you can't find a hosted SMTP server online, you can always install one locally on your box. This will allow you to modify the email address of the sender to make it appear as if it is coming from gmail.
As far as I'm aware you can't. That is what is called relaying. Relaying is what the spammers use to send mail pretending to be whoever. Its a security hole. If you want to send as someone else you need to create another account.
How do you send messages from a different address using Gmail and Java?
For gmail, you most likely can't ... for obvious reasons.
In the Java case, whether you can or can't do this depends on the mail server that your Java application connects to. A mail server typically can be configured to allow this, but it has obvious issues so a responsible mail server admin is not going to allow this, except in controlled circumstances.
I am trying to send simple text mail to myself from a servlet using Java Mail API. I wonder how to best approach this in order to avoid daily sent limits meant to restrict sending mail to other people.
How does a mail server receive email? From what information I could find, it is through the SMTP protocol? When the receiver happens to be local, instead of a relay the SMTP server assumes the role of local mail delivery agent. Is that correct? Any problems I could bump into when I connect directly to my SMTP server?
To avoid any confusion, I want my servlet to act as an SMTP server, NOT a mail client that connects to one. I want to make a mail server to RECEIVE a message going to my mail box, not relay one to other people.
Yes, SMTP is the protocol that a client uses to send an email message to a remote server.
Depending on the server software, there may be ways to send a message to a local server without using SMTP, but (as far as I know) the Java mail framework doesn't know about any of those, it can only use SMTP. So if there are limits on how much you can send, you'll just have to fix those limits directly.
If you want to test sending mail from your java application, and you have no development server to connect to, then install a local email server (hmailserver for windows, postfix for *nix).
Configure your email server to only receive email from localhost, and to only deliver to local clients (that way you wont spam the world with your test emails).
Once your happy with your application, you can point it at a production email server. How you connect and the amount of emails you can send will depend on your provider. If you are hosting your own email server you should get professional advice (or do a lot of reasearch) to prevent becoming a spammer, or having a spammer abuse your service (google for open relay).
The postfix site has plenty of good documentation and hmail server has a very good gui.