Note that there are some explanatory texts on larger screens.

plurals
  1. POcannot parse headers to create MIME message
    primarykey
    data
    text
    <p>I'm trying to send messages only to myself, not out to or through the intertubes, based on the <a href="http://commons.apache.org/net/" rel="nofollow">Apache NNTP API</a>. The particular class involved takes an <a href="http://en.wikipedia.org/wiki/Nntp" rel="nofollow">NNTP message</a> and attempts to parse it into a regular MIME type message as so:</p> <pre><code>package net.bounceme.dur.nntp; import java.util.Arrays; import java.util.Enumeration; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import java.util.Properties; import javax.mail.Address; import javax.mail.Header; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.NoSuchProviderException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class MessageSender { private final static Logger LOG = Logger.getLogger(MessageSender.class.getName()); private String header; private String body; private Properties p; private Session session; private MimeMessage message; private MessageSender() { } public MessageSender(Properties p, String... s) throws Exception { header = s[0]; body = s[1]; this.p = p; populate(); } private void populate() throws Exception { String lines[] = header.split("\\n"); session = Session.getDefaultInstance(p, null); message = new MimeMessage(session); LOG.fine("\n\n\n\nnew message************\n\n\n\n"); for (String s : lines) { if (!s.contains("comp.lang.java.help")) { message.addHeaderLine(s); } } message.setContent(message, body); String recipient = p.getProperty("recipient"); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient)); try { send(); } catch (javax.mail.internet.ParseException e) { LOG.warning(e.toString()); } catch (com.sun.mail.smtp.SMTPAddressFailedException e) { LOG.warning(e.toString()); List&lt;Address&gt; addresses = Arrays.asList(message.getAllRecipients()); for (Address a : addresses) { LOG.info(a.toString()); } } } private void send() throws Exception { String protocol = p.getProperty("protocol"); String host = p.getProperty("host"); int port = Integer.valueOf(p.getProperty("port")); String username = p.getProperty("username"); String password = p.getProperty("password"); Transport transport = session.getTransport(protocol); LOG.log(Level.FINE, "{0}{1}{2}{3}{4}", new Object[]{protocol, host, port, username, password}); Enumeration enumOfHeaders = message.getAllHeaders(); while (enumOfHeaders.hasMoreElements()) { Header h = (Header) enumOfHeaders.nextElement(); LOG.log(Level.FINE, "\n\n\nHEADER\n{0}\n{1}", new Object[]{h.getName(), h.getValue()}); } transport.connect(host, port, username, password); transport.sendMessage(message, message.getAllRecipients()); } } </code></pre> <p>But I'm having trouble with the headers:</p> <pre><code>init: Deleting: /home/thufir/NetBeansProjects/apache_nntp/build/built-jar.properties deps-jar: Updating property file: /home/thufir/NetBeansProjects/apache_nntp/build/built-jar.properties Compiling 1 source file to /home/thufir/NetBeansProjects/apache_nntp/build/classes compile: run: 200 Leafnode NNTP Daemon, version 1.11.8 running at localhost (my fqdn: dur.bounceme.net) GROUP comp.lang.java.help 211 35 3 37 comp.lang.java.help group selected HEAD 3 221 3 &lt;7e60dce5-09d7-4cee-bbc1-137207f03dd0@googlegroups.com&gt; article retrieved - head follows BODY 3 222 3 &lt;7e60dce5-09d7-4cee-bbc1-137207f03dd0@googlegroups.com&gt; article retrieved - body follows Feb 24, 2013 3:05:04 AM net.bounceme.dur.nntp.MessageSender populate WARNING: javax.mail.internet.ParseException: Expected '/', got wrote HEAD 4 221 4 &lt;kfpdt3$5g9$1@dont-email.me&gt; article retrieved - head follows BODY 4 222 4 &lt;kfpdt3$5g9$1@dont-email.me&gt; article retrieved - body follows Exception in thread "main" javax.mail.SendFailedException: Invalid Addresses; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 450 4.1.8 &lt;markspace@nospam.nospam&gt;: Sender address rejected: Domain not found at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1863) at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1119) at net.bounceme.dur.nntp.MessageSender.send(MessageSender.java:80) at net.bounceme.dur.nntp.MessageSender.populate(MessageSender.java:54) at net.bounceme.dur.nntp.MessageSender.&lt;init&gt;(MessageSender.java:35) at net.bounceme.dur.nntp.ArticleReader.&lt;init&gt;(ArticleReader.java:28) at net.bounceme.dur.nntp.Driver.&lt;init&gt;(Driver.java:13) at net.bounceme.dur.nntp.Driver.main(Driver.java:17) Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 450 4.1.8 &lt;markspace@nospam.nospam&gt;: Sender address rejected: Domain not found at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1730) ... 7 more Java Result: 1 BUILD SUCCESSFUL (total time: 6 seconds) </code></pre> <p>Now, I appreciate that there's no domain for the sender. Nonetheless, I want to go ahead and send the message. Do I need to change the sender? I'd like to muck with the headers as little as possible.</p> <p>If there's a better way to convert NNTP --> MIME Message I'm certainly open to suggestions. I'm already dropping the newsgroup header as that seems problematic for reasons I don't understand. Basically, I just can't figure out how to parse these headers so that they create a valid message to send.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload