1 / 25

James

James. http://wiki.apache.org/james/JamesQuickstart. More links. http://james.apache.org/server/james_and_sendmail.html http://www.ibm.com/developerworks/java/library/j-james2.html http://www.ibm.com/developerworks/java/library/j-james1.html http://www.roseindia.net/javamail/

levia
Download Presentation

James

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. James http://wiki.apache.org/james/JamesQuickstart

  2. More links • http://james.apache.org/server/james_and_sendmail.html • http://www.ibm.com/developerworks/java/library/j-james2.html • http://www.ibm.com/developerworks/java/library/j-james1.html • http://www.roseindia.net/javamail/ • http://wiki.apache.org/james/

  3. Click on run.bat

  4. config • As per quickstart instructions get your dns (domain name server) and ip (internet protocol address) using (for example) C:\> ipconfig /all You need to edit the config file at …/app/james/SAR-INF/config.xml with the dns number and authorized ip address. See example in james quickstart.

  5. Connect to james • When running: Using PHOENIX_HOME: C:\james\james-2.3.1 Using PHOENIX_TMPDIR: C:\james\james-2.3.1\temp Using JAVA_HOME: C:\Program Files\Java\jdk1.6.0_03 Phoenix 4.2 James Mail Server 2.3.1 Remote Manager Service started plain:4555 POP3 Service started plain:110 SMTP Service started plain:25 NNTP Service started plain:119 FetchMail Disabled • To change settings, addusers, etc: prompt>telnet localhost 4555

  6. James commands: telnet localhost 4555 help Currently implemented commands: help display this help listusers display existing accounts countusers display the number of existing accounts adduser [username] [password] add a new user verify [username] verify if specified user exist deluser [username] delete existing user setpassword [username] [password] sets a user's password setalias [user] [alias] locally forwards all email for 'user' to 'alias' showalias [username] shows a user's current email alias unsetalias [user] unsets an alias for 'user' setforwarding [username] [emailaddress] forwards a user's email to another email address showforwarding [username] shows a user's current email forwarding unsetforwarding [username] removes a forward user [repositoryname] change to another user repository shutdown kills the current JVM (convenient when James is run as a daemon) quit close connection listusers Existing accounts 1 user: Higgins quit

  7. Mail client used by configtest (next slide) • In slide notes

  8. ConfigTest uses MailClient with fictitious users public class JamesConfigTest { public static void main(String[] args) throws Exception { // CREATE CLIENT INSTANCES MailClient redClient = new MailClient("red", "localhost"); MailClient greenClient = new MailClient("green", "localhost"); MailClient blueClient = new MailClient("blue", "localhost"); // CLEAR EVERYBODY'S INBOX redClient.checkInbox(MailClient.CLEAR_MESSAGES); greenClient.checkInbox(MailClient.CLEAR_MESSAGES); blueClient.checkInbox(MailClient.CLEAR_MESSAGES); Thread.sleep(500); // Let the server catch up // SEND A COUPLE OF MESSAGES TO BLUE (FROM RED AND GREEN) redClient.sendMessage( "blue@localhost", "Testing blue from red", "This is a test message"); greenClient.sendMessage( "blue@localhost", "Testing blue from green", "This is a test message"); Thread.sleep(500); // Let the server catch up // LIST MESSAGES FOR RED redClient.checkInbox(MailClient.SHOW_AND_CLEAR); } }

  9. After adding users c:\Program Files\Java\jdk1.6.0_03\bin>java JamesConfigTest Clear INBOX for red@localhost Clear INBOX for green@localhost Clear INBOX for blue@localhost SENDING message from red@localhost to blue@localhost SENDING message from green@localhost to blue@localhost Show and Clear INBOX for blue@localhost No messages in inbox c:\Program Files\Java\jdk1.6.0_03\bin>

  10. Modified configtest to take commanline args public class JamesConfigTest { public static void main(String[] args) throws Exception { // CREATE CLIENT INSTANCES MailClient redClient = new MailClient(args[0], "www.mycookbook.com"); // LIST MESSAGES FOR BLUE (EXPECT MESSAGES FROM RED AND GREEN) redClient.checkInbox(MailClient.SHOW_AND_CLEAR); } }

  11. telnet localhost 25 220 MATH-Higgindm06 SMTP Server (JAMES SMTP Server 2.3.1) ready Tue, 21 Oct 2008 19:59:51 -0400 (EDT) ehlo mycookbook 250-MATH-Higgindm06 Hello mycookbook (www.mycookbook.com [127.0.0.1]) 250-PIPELINING 250 ENHANCEDSTATUSCODES mail from: <higgindm@oneonta.edu> 250 2.1.0 Sender <higgindm@oneonta.edu> OK rcpt to: <red@mycookbook.com> 250 2.1.5 Recipient <red@mycookbook.com> OK data 354 Ok Send data ending with <CRLF>.<CRLF> subject: not sure how to get subject &c content content . 250 2.6.0 Message received Connection to host lost. c:\Borland\BCC55\bin>

  12. My sendmail app import java.security.Security; import java.util.Properties; import com.sun.mail.smtp.*; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class JamesTest3 { private static Session getMailSession() throws Exception { Properties mailProperties = new Properties(); mailProperties.setProperty("mail.transport.protocol", "smtp"); mailProperties.setProperty("mail.smtp.host", "localhost"); System.out.println("got to here 1"); return Session.getInstance(mailProperties, null); }

  13. My sendmail app public static void main(String[] args) { try{ // CREATE CLIENT INSTANCES // MailClient redClient = new MailClient("red", "localhost"); Session mailSession=getMailSession(); MimeMessage msg = new MimeMessage(mailSession); msg.setFrom(new InternetAddress("higgindm@mycookbook.com")); msg.addRecipient(Message.RecipientType.TO, new InternetAddress("higgindm@oneonta.edu")); msg.setSubject("james server...from an application"); String html = "a plain text message from james using an application jamestest3"; msg.setContent(html, "text/html"); Transport transport = mailSession.getTransport("smtp"); System.out.println("got to here 2"); transport.connect("localhost","Higgins", "jack"); System.out.println("got to here 3"); msg.saveChanges(); transport.sendMessage(msg, msg.getAllRecipients()); transport.close(); System.out.println("got to here 4"); }catch (Exception e){System.out.println("in catch for error "+e.toString());} } }

  14. settings in config file in slide notes • You must set ip & dns in config • <dnsserver> <servers> <server> 10.0.0.15 </server> <server> 10.0.0.22 </server> </servers> <authoritative> false </authoritative> </dnsserver>

  15. Domain name • You must set a domain name like mydomain.com • <servernames> <servername> foobar.com </servername> </servernames> • Determine the DNS server to use. On Windows, type ipconfig /all and look for the DNS servers. On Unix, look at /etc/resolv.conf. You will need this information in step #9. • Determine your local IP address for reference. On Windows, run <code>ipconfig</code> to see your IP Address. On Unix, run /sbin/ifconfig and look for your inet addr. • Check the DNS configuration of the domain you want James to handle using http://www.dnsreport.com. If you want to handle email for foobar.com, put that domain name in the DNS Report field. On the report, you will want to check the MX record section to make sure the MX records point to the IP address you determined in the previous step, and that everything else about your domain's MX passes. • Edit apps/james/SAR-INF/config.xml. Look over a section called <servernames> and put the domain you want to accept messages for within <servername> elements, e.g.,

  16. Notes from Hunter… odds & ends pg 550…email servlet import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import com.oreilly.servlet.MailMessage; import com.oreilly.servlet.ParameterParser; import com.oreilly.servlet.ServletUtils;

  17. Mailservlet continued public class MailServlet extends HttpServlet { static final String FROM = "MailServlet"; static final String TO = "feedback-folks@attentive-company.com"; public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); ParameterParser parser = new ParameterParser(req); String from = parser.getStringParameter("from", FROM); String to = parser.getStringParameter("to", TO); try { MailMessage msg = new MailMessage(); // assume localhost msg.from(from); msg.to(to); msg.setSubject("Customer feedback"); PrintStream body = msg.getPrintStream(); Enumeration enum = req.getParameterNames();//change name enum while (enum.hasMoreElements()) { String name = (String)enum.nextElement(); if (name.equals("to") || name.equals("from")) continue; // Skip to/from String value = parser.getStringParameter(name, null); body.println(name + " = " + value); } body.println(); body.println("---"); body.println("Sent by " + HttpUtils.getRequestURL(req)); msg.sendAndClose(); out.println("Thanks for the submission..."); } catch (IOException e) { out.println("There was a problem handling the submission..."); log("There was a problem sending email", e); } }}

  18. It works but…. • You’ll need your own smtp server… that’s a simple-mail-transfer-protocol server. • So… google smtp server… • I found and used this one: • http://www.softstack.com/freesmtp.html

  19. Website…minimal installation instructions

  20. Here’s the cheesy interface: note active connection

  21. Running a mailtest application import java.security.Security; import java.util.Properties; import com.sun.mail.smtp.*; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class JamesTest2 { private static Session getMailSession() throws Exception{ Properties mailProperties = new Properties(); mailProperties.setProperty("mail.transport.protocol", "smtp"); mailProperties.setProperty("mail.smtp.host", "localhost"); System.out.println("got to here 1"); return Session.getInstance(mailProperties, null);} public static void main(String[] args) throws Exception { // CREATE CLIENT INSTANCES // MailClient redClient = new MailClient("red", "localhost"); MimeMessage msg = new MimeMessage(getMailSession()); System.out.println("got to here 2"); msg.setFrom(new InternetAddress("higgindm@oneonta.edu")); msg.addRecipient(Message.RecipientType.TO, new InternetAddress("higgindm@oneonta.edu")); msg.setSubject("james server"); msg.setText("sending mail with james...."); Transport.send(msg); System.out.println("got to here 4"); }}

  22. Project structure

  23. Running the mailtest application • Javaee-api-5.0.4.jar or mail.jar or any of a bunch of other jar files with the com.sun.mail.smtp must be in the classpath. • I built/ran this is eclipse. Eclipse could not resolve the classpath issue so I added the javaee to the build path. • It did not actually send mail until I included the config.xml. The only thing I changed in that huge file was my dns server number.

  24. Got the mail config.xml in slide notes.

  25. Have to add a webapp for this…

More Related