Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Sending Email

Options
  • 04-12-2009 7:01pm
    #1
    Closed Accounts Posts: 404 ✭✭


    Dedicated server set-up

    We send simple alert emails from our Apache Tomcat application.
    We use our hosts email server to do this.

    Requirement
    I want to stop relying on the host email server, but don't want or need the hassle of maintaining a full emial server.

    Questions
    Any simple way to send emails using Java that doesn't rely on an email server ?
    or
    Any very light weight email sever I can install, just need to send email, don't want to have to install name servers etc.


Comments

  • Registered Users Posts: 1,998 ✭✭✭lynchie


    kenbrady wrote: »
    Dedicated server set-up

    We send simple alert emails from our Apache Tomcat application.
    We use our hosts email server to do this.

    Requirement
    I want to stop relying on the host email server, but don't want or need the hassle of maintaining a full emial server.

    Questions
    Any simple way to send emails using Java that doesn't rely on an email server ?
    or
    Any very light weight email sever I can install, just need to send email, don't want to have to install name servers etc.

    Sending emails requires the use of an SMTP server regardless whether its on your own machine or using your ISP's one.

    If you dont want to use your ISP's server, simply install an smtp server locally (easiest way is to install linux) enable message relaying and point your apps smtp server at your local one.


  • Moderators, Science, Health & Environment Moderators Posts: 10,079 Mod ✭✭✭✭marco_polo


    kenbrady wrote: »
    Dedicated server set-up

    We send simple alert emails from our Apache Tomcat application.
    We use our hosts email server to do this.

    Requirement
    I want to stop relying on the host email server, but don't want or need the hassle of maintaining a full emial server.

    Questions
    Any simple way to send emails using Java that doesn't rely on an email server ?
    or
    Any very light weight email sever I can install, just need to send email, don't want to have to install name servers etc.

    Apache James is very easy to use and install.

    http://james.apache.org/


  • Registered Users Posts: 7,739 ✭✭✭mneylon


    If the emails are going to you it should be fine, but if you're sending emails to 3rd parties you may run into issues with spam filters etc, if your mail isn't crafted very carefully


  • Closed Accounts Posts: 404 ✭✭kenbrady


    It's only to send simple notice emails as part of application.
    Don't want to rely on hosting company servers, to keep portable if I want to switch host.

    Here is code that works and is very light weight, will stick it in a thread as a separate process in production code, in case there is some delays.

    Solution 1
    Problems, I only have email addresses ie (john@boards.ie) so if the email server is not 'mail.boards.ie' it will fail. Also could be some spam filter issues as it is not send from a proper email server.

    Solution 2
    Other option is to use gmail stmp server, but that has a bit more overhead as it needs authentication. Plus if gmail goes down, nothing I can do about it.
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.net.Socket;
    
    public class SendEmail {
    
        public static void main(String args[]) {
            SendEmail se = new SendEmail("mail.other.com", "bill@other.com");
        }
    
        public SendEmail(String mailServer,String recipient) {
            try {
                Socket s = new Socket(mailServer, 25);
                BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream(), "8859_1"));
                BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream(), "8859_1"));
    
                send(in, out, "HELO Company");
                send(in, out, "MAIL FROM: <info@company.ie>");
                send(in, out, "RCPT TO: " + recipient);
                send(in, out, "DATA");
                send(out, "Subject: Email test");
                send(out, "From: Company <info@company.ie>");
                send(out, "\n");
                // message body
                send(out, "This is the message body");
                send(out, "\n.\n");
                send(in, out, "QUIT");
                s.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
    
        }
    
        public void send(BufferedReader in, BufferedWriter out, String s) {
            try {
                out.write(s + "\n");
                out.flush();
                System.out.println(s);
                s = in.readLine();
                System.out.println(s);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public void send(BufferedWriter out, String s) {
            try {
                out.write(s + "\n");
                out.flush();
                System.out.println(s);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    


  • Registered Users Posts: 7,739 ✭✭✭mneylon


    kenbrady wrote: »
    It's only to send simple notice emails as part of application.
    To who though? You or someone else?

    If you're sending notifications to users you can and will run into issues if the volume of mails from the server goes from zero to $largenumber very quickly

    Apart from anything else make sure that the server is setup correctly in terms of A records and PTR records.


  • Advertisement
  • Closed Accounts Posts: 404 ✭✭kenbrady


    Blacknight wrote: »
    To who though? You or someone else?

    If you're sending notifications to users you can and will run into issues if the volume of mails from the server goes from zero to $largenumber very quickly

    Apart from anything else make sure that the server is setup correctly in terms of A records and PTR records.
    emails going to users, so lots of different addresses.

    We are using google stmp server from now.

    We'll have to install our own email server eventually, so we will be moving to apache james. Or we might rent access to an 3rd party email server if it is cost effect to make it less of a technical issue for us.

    Solved


Advertisement