Sending mail from a java app without using an external SMTP server - java

JavaMail requires that you specify an external SMTP server when sending mail. I want to have my java app send email directly without having to use an external SMTP server such as postfix or sendmail.
Can anyone recommend a library which provides this kind of functionality?
Ive done some googling and have come up with nothing.

It's not trivial to send mail yourself. To start with, you have to deal with DNS (MX records), queuing, connection management and maybe signing (DKIM). So you wouldn't find any light-weight library like JavaMail to do this.
Your best bet is JAMES,
http://james.apache.org/

Related

Is Mail server required for sending email?

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.

Is it possible to send mail using Java when gmail access is blocked

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.

How to put email to my own mailbox with Java mail API

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.

Sending Email using Java

I want my Java application to send out emails to users. But I cant get a good solution.
Now, I got some on Google but they use a SMTP server which I dont have. I was wondering if setting up one on my Linux machine would be easy?
So, I am using mailx now to send out emails but it sends emails from root which is definately not good. Is there any way to send out emails from a proper email using java? like you can do in php and other languages?
Use commons-email to send email from java in a simple, straightforward way (see the docs).
You need an SMTP server always - even in "php and other languages", but perhaps you don't know you need it, because it is bundled in your LAMP package.
One solution is to use google as an SMTP server. Either via your account, or via google apps. Otherwise setting up an smtp server (postfix for example) linux appears trivial, but isn't - you have to take into consideration many things - see this post by Jeff Atwood.
So ultimately, I'd suggest using the options provided by google.
if you'r looking to host your own mail server, then apache james is a pretty good option.
or other solution could be using a third-party mailservers such as gmail or yahoo; and use the JavaMail API to send emails.
If you don't have an SMTP server, Asprin is a send-only SMTP server, which is a pretty good fit. It suffers from the same problem any do-it-yourself SMTP server will, in that it will look more like a Spam source, so using a proper SMTP server used for e-mail should be done if possible.

Integration of an email server in a Java EE application

I am building a web application that has to be able to do the following:
Send emails to the (external) addresses registered by the users (say, Gmail, Yahoo Mail, etc).
Send/receive emails to local mailboxes that live in the application. These are more "messages" in that sense.
What are the potential open source technologies I could integrate with here? Thanks for your inputs.
So, you want a SMTP server? If you want to have it in Java, then I can suggest to pick Apache James. But in fact every decent SMTP server would suffice. You can just use JavaMail API, or the more convenienced Apache Commons Email which is built on top of JavaMail API, to talk with any SMTP server to send/read emails.
If you didn't already realize, you can also just make use of an existing SMTP server provided by your ISP or the web hosting. In this case only JavaMail or Commons Email would have been sufficient.
While Commons Email will help you get the sending part done, receiving email will require that you access mailboxes via IMAP or POP through the Java Mail API.
Java Mail is a little cumbersome to use, but this Stackoverflow question has a working IMAP sample to help you get started.
There is a JCA (Java Connector Architecture) adapter that makes your Java EE server open port 25 for receiving mails.
http://sourceforge.net/projects/mailra/
A quite old tutorial which is incomplete with some examples for IMAP watching can be found here:
https://community.jboss.org/wiki/InboundJavaMail
A general introduction to JCA can be found here:
http://www.adam-bien.com/roller/abien/entry/a_simple_transactional_file_jca

Categories

Resources