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.
Related
I'm working on a project I'm Java with regards to outlook.
Here I'm able to do all the functions like Read a mail, write a mail, reply to a mail etc...
But now we've been thinking of taking it to the next level.
Our plan is as below.
We have an email address like info#myDomain.com, when ever an email is sent to this address, I need to reply them. Here basically customers send an email asking for some data, and we've the data available in our portal, and we just need to send it.
The response would be Like thank you for contacting us, we will get back to you soon. Mean while please look into this {URL}.
And this has to be done automatically when ever there is an email hit to this particular email address.
Couple of questions:
- should my machine be on the whole day to get this thing done.
- is there a way that a Java application can automatically monitor my inbox to see for this case match.
- Also, can I have this running in the bg.
Can someone please point me into the right direction/approach where can I can start working on this task.
Thanks
when ever an email is sent to this address, I need to reply them.
For this you need to monitor your email account fro incoming emails. Here is one of the way to do this
The response would be Like thank you for contacting us, we will get back to you soon. Mean while please look into this {URL}.
Once you receive an email (using above email monitoring approach), you need to call a method that sends the reply with above format
And this has to be done automatically when ever there is an email hit to this particular email address.
Above two steps accomplishes this task.
should my machine be on the whole day to get this thing done
Basically, you will need an application server (like tomcat) where your above java program is deployed. So, yes this server needs to be running and available all the time.
is there a way that a Java application can automatically monitor my inbox to see for this case match
Check point 1
Also, can I have this running in the bg
You can run tomcat as a service in windows (more info). It has many advantages, automatic startup on boot being the one. Similar implementations are also available for other OS.
So, in short, this can be accomplished. It is bit complex but not much difficult. Cheers
I have working code to send mail using gmail smtp. It's working on my machine, but when I'm trying to run same code from my office system, then it showing error Unable to Connect SMTP Server. So, I was wondering, is it possible to send mail by bye-passing local/office network ? Any work-around ?
PS: I can't use my corporate email address, since it's internal task.
What you need to do is install a mail server on your machine and use that mail server to send emails. There are a lot of opensource and/or free options available. I have used hMailServer in the past (on Windows7), and it seemed to work for me, just the way I wanted it to. One possible downside of using this approach is that your emails may sometimes end up in the spam folders of your intended recipients.
However, you will need Administrator privileges to install most mailservers.
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 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.