JavaMail - RFC822

Discussion in 'Java' started by Rico, Dec 23, 2004.

  1. Rico

    Rico Guest

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Pattern p = Pattern.compile("@[a-zA-Z_0-9<>\\-\\;\\,\\.]*@");
    Matcher m = p.matcher(user_info.getEmailAddress());
    boolean b = m.find();

    if (!b) // Does _not_ match 2 or more email addresses
    {
    InternetAddress[] addr = {new InternetAddress(user_info
    .getEmailAddress(), user_info.getName())};
    msg.addRecipients(Message.RecipientType.TO, addr);
    } else
    msg.addRecipients(Message.RecipientType.TO, user_info
    .getEmailAddress());
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    In the above code, I use the regular expression to detect whether I
    have at least 2 email addresses to send the message to.
    This is because I can't figure out how to attach a 'name' string
    to a group of email addresses in JavaMail. So in the first case when
    the match fails (only 1 email address) I can afford to put the name
    string, otherwise, I don't.

    Previously a hyphen in the domain name caused the regular expression
    to fail to detect 2 email addresses because I didn't include it as a
    possible literal.

    Now, if I use ; , wanting to be RFC822 compliant,
    Javamail complains that the semi-colon is illegal: not in group.
    Trivial fix is to replace the semi-colon with comma.

    Yet, not that I lack other things to do, I did go and read RFC822 to
    find out how to associate a name with a list of email addresses and
    they say:

    group = phrase ":" [#mailbox] ";"

    The part between square brackets is my list of email addresses, separated
    by commas.

    So, that'd mean I use:
    "marc and tommy":,;

    Not surprisingly, it doesn't work.

    Maybe someone could please help me make sense of what I've read then.
    How do I associate a name string with a group of email addresses?
    And where does JavaMail expect the semi-colon to be for a group? Thanks.

    Rico.
     
    Rico, Dec 23, 2004
    #1
    1. Advertising

  2. In article <>,
    Rico <> wrote:

    > Now, if I use ; , wanting to be RFC822 compliant,
    > Javamail complains that the semi-colon is illegal: not in group.
    > Trivial fix is to replace the semi-colon with comma.
    >
    > Yet, not that I lack other things to do, I did go and read RFC822 to
    > find out how to associate a name with a list of email addresses and
    > they say:
    >
    > group = phrase ":" [#mailbox] ";"
    >
    > The part between square brackets is my list of email addresses, separated
    > by commas.
    >
    > So, that'd mean I use:
    > "marc and tommy":,;
    >
    > Not surprisingly, it doesn't work.
    >
    > Maybe someone could please help me make sense of what I've read then.
    > How do I associate a name string with a group of email addresses?
    > And where does JavaMail expect the semi-colon to be for a group? Thanks.


    Maybe the problem isn't with JavaMail, but with your SMTP server. Group
    syntax is somewhat arcane, and I wouldn't be surprised if there are some
    servers that don't recognize it.

    --
    Barry Margolin,
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
     
    Barry Margolin, Dec 23, 2004
    #2
    1. Advertising

  3. Rico

    GaryM Guest

    Rico <> wrote in
    news:p:


    > Maybe someone could please help me make sense of what I've read
    > then. How do I associate a name string with a group of email
    > addresses? And where does JavaMail expect the semi-colon to be for
    > a group? Thanks.
    >



    Rico, I tested this out and it works fine. Perhaps you can post your
    code and any exceptions along with debug log? Here's my test code.

    // My test code:

    String group = "\"marc and tommy\":,;";

    // Does Javamail like the group construction?
    try {
    InternetAddress addr = new InternetAddress(group);
    } catch (AddressException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    System.exit(1);
    }

    System.setProperty("mail.debug", "true");
    System.setProperty("mail.smtp.auth", "true");
    System.setProperty("mail.transport.protocol", "smtp");

    Session session = Session.getDefaultInstance(System.getProperties());
    MimeMessage mm = new MimeMessage(session);

    // Create and send the message
    try {
    mm.setFrom(new InternetAddress(""));
    mm.setRecipients(Message.RecipientType.TO, group);
    mm.setSubject("Test groups");
    mm.setText("This is a test");
    mm.saveChanges();
    Transport transport= session.getTransport();
    transport.connect("your_server");
    transport.sendMessage(mm, mm.getAllRecipients());
    } catch (MessagingException e1) {
    e1.printStackTrace();
    }
     
    GaryM, Dec 24, 2004
    #3
  4. Rico

    Rico Guest

    On Fri, 24 Dec 2004 09:56:04 -0500, GaryM wrote:
    > Rico <> wrote in
    >> Maybe someone could please help me make sense of what I've read
    >> then. How do I associate a name string with a group of email
    >> addresses? And where does JavaMail expect the semi-colon to be for
    >> a group? Thanks.

    >
    > Rico, I tested this out and it works fine. Perhaps you can post your
    > code and any exceptions along with debug log? Here's my test code.


    Thanks a lot. Things work fine with Sun's JavaMail. I ran into a couple of
    glitches with GNU's version.
    In both cases it's better to not create an InternetAddress or
    InternetAddress[] from the group because MimeMessage.getAllRecipients()
    fails. Using the string itself is all good for Sun; attachment included.

    With GNU's JavaMail I run into some GSSException and some missing krb5.ini
    file even though the email does get sent out but to only the first address
    in the group and to the CC field. Furthermore, the PDF attachment is seen
    as a text document. I've subscribed to the GNU JavaMail mailing list a few
    days back. I'll email them about it.

    > // My test code:
    > String group = "\"marc and tommy\":,;";
    >
    > // Does Javamail like the group construction?
    > try {
    > InternetAddress addr = new InternetAddress(group);
    > } catch (AddressException e) {
    > // TODO Auto-generated catch block
    > e.printStackTrace();
    > System.exit(1);
    > }
    >
    > System.setProperty("mail.debug", "true");
    > System.setProperty("mail.smtp.auth", "true");
    > System.setProperty("mail.transport.protocol", "smtp");
    >
    > Session session = Session.getDefaultInstance(System.getProperties());
    > MimeMessage mm = new MimeMessage(session);
    >
    > // Create and send the message
    > try {
    > mm.setFrom(new InternetAddress(""));
    > mm.setRecipients(Message.RecipientType.TO, group);
    > mm.setSubject("Test groups");
    > mm.setText("This is a test");
    > mm.saveChanges();
    > Transport transport= session.getTransport();
    > transport.connect("your_server");
    > transport.sendMessage(mm, mm.getAllRecipients());
    > } catch (MessagingException e1) {
    > e1.printStackTrace();
    > }


    Rico.
     
    Rico, Dec 25, 2004
    #4
  5. Rico

    Rico Guest

    On Thu, 23 Dec 2004 16:14:07 -0500, Barry Margolin wrote:
    > In article <>,
    > Rico <> wrote:
    >> Now, if I use ; , wanting to be RFC822 compliant,


    >> "marc and tommy":,;
    >>
    >> Not surprisingly, it doesn't work.
    >>
    >> Maybe someone could please help me make sense of what I've read then.
    >> How do I associate a name string with a group of email addresses?
    >> And where does JavaMail expect the semi-colon to be for a group? Thanks.

    >
    > Maybe the problem isn't with JavaMail, but with your SMTP server. Group
    > syntax is somewhat arcane, and I wouldn't be surprised if there are some
    > servers that don't recognize it.


    Thanks Barry.
    I guess I could have a loop that extracts the individual addresses as
    tokens using space, comma and semi-colon as separators and add them into
    an InternetAddress[].
    I think Sun's JavaMail might save me the trouble though.

    Rico.
     
    Rico, Dec 25, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vladimir Litovka

    rfc822 regexp

    Vladimir Litovka, Feb 4, 2004, in forum: Perl
    Replies:
    1
    Views:
    802
  2. Darren Davison

    Dates from Strings in RFC822 format

    Darren Davison, Jul 23, 2003, in forum: Java
    Replies:
    2
    Views:
    1,566
    Shripathi Kamath
    Jul 23, 2003
  3. Malcolm Dew-Jones

    Q: xml for rfc822/mime

    Malcolm Dew-Jones, May 5, 2004, in forum: XML
    Replies:
    1
    Views:
    503
    Johannes Koch
    May 5, 2004
  4. shilpa
    Replies:
    5
    Views:
    6,229
    akila_natarajan
    May 12, 2011
  5. Michael B Allen

    rfc822.py date parsing problem

    Michael B Allen, Jan 17, 2004, in forum: Python
    Replies:
    0
    Views:
    309
    Michael B Allen
    Jan 17, 2004
Loading...

Share This Page