I am not sure do i need to configure some mail server (like james) to send email from java api
like explained at this Java email send code example
No but its not a good idea.
When you want to use javax.mail session you need a mail server which accepts smtp connection from your app. This is preffered why.
But you could also write a socket based adapter which directly tries to deliver the mail to the receivers mail server by connecting by smtp and handle the protocol your self. That is theoreticaly, because most email server would not accept your application, because there spam protection will block you.
So my advice is. Don't think to much about this. Use a locale mailserver like james or one of the millions smtps proxies out there for development. And later in production change configuration to a well setup mailserver (most called MTA) where you can be sure that your mails will be delivered.
You do not need to set up one yourself. Mail providers, such as GMail and Outlook for instance, expose their own mail servers which you can use to transmit email messages.
Note however that in such cases, email transmission might eventually be blocked so as to discourage the delivery of SPAM mail.
yes :)
in this example it is installed at localhost, so mail is passed to another service within the same box. of course, you can use an external server, too - for example if you have a development system home, than utilize the mail server of your ISP.
Related
please how to test sending email without real server in java knowing that email is send in a project A and I want to test sending in project B
Email cannot be "sent" without an email server.
Email is modeled after a physical mail system, with a few changes. The "sending" is the equivlent to the dropping the letter off at a post office. It is not possible to do point-to-point email.
Email clients then open their "PO Box" or "Mailbox" on the server, and perhaps (it is optional) then downloads the mail into the local machine.
In fact, the "sending" of an email is a number of back-and-forth communication with the email server using SMTP. Basically sending an email consists of telling the server hello, then asking about it's capabilities, and eventually asking it to validate addresses and accept a body (and optionally attachments).
So, if you really need to send a mail to a product in project B, and you cannot rely on a standalone server, you need to create a server in project B.
I think that you should consider mocking the mail sending. Depending on the frameworks you use, you should be able to find a good way to do it. Here is a blog illustrating a possible mechanism: http://blog.nutpan.com/2012/03/mock-testing-for-java-mail.html?m=1
You can also consider using a mocking framework like easymock or mockito to test it.
I started testing Mail API; All examples I could see require to know port to send a message; and I am just wondering is there a way to send email with Mail API if you don't know port but recipient email only? If so I would be glad to see some snippets in this direction.
Thanks
There are default ports for all the standard email protocols. If your mail server is using the default port (and almost all do), you don't need to specify the port.
But it sounds like you want to find the mail server to use to send to a particular recipient. That's a completely different issue.
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.