Mail userids with space char in it.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ak_sharma
Posted On:   Thursday, February 14, 2002 08:51 AM


How to get access to the mailbox where user id contains space in it? I got few mail users created with space char in it (MS Exchange and Lotus Notes both).
While same code works for the mail users without space char in their name but it throws AuthenticationFailedException for the mail users with space char in their name. Any help will be greatful.

Re: Mail userids with space char in it.

Posted By:   Chandra_Patni  
Posted On:   Wednesday, February 20, 2002 07:23 PM

For JavaMail 1.2, you don't have do anything for imap authentication if username contains white spaces. You should add double quotes around user name for InternetAddress and for client which doesn't do this automcatically. For example, an imap session using telnet on port 143 would be as follows.

Client>
a001 LOGIN "Chandra Patni" javaiscool
Server>
a001 OK LOGIN completed.
Client>
a002 SELECT INBOX
Server>
* 4 EXISTS
* 0 RECENT
* FLAGS (Seen Answered Flagged Deleted Draft)
* OK [PERMANENTFLAGS (Seen Answered Flagged Deleted Draft)]
* OK [UNSEEN 2] Is the first unseen message
* OK [UIDVALIDITY 1803] UIDVALIDITY value.
a002 OK [READ-WRITE] SELECT completed.
Client>
a003 LOGOUT

However, the SMTP server seem to have problem with such addresses. I could not make sendmail/reply work. The following example connects to an Exchange server and creates a Message which is appended to INBOX.

import java.io.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class TestMail1 {
public static void main (String args[]) throws Exception {
String username = "Java Duke";
String password = "welcomeduke";
String host = "myimap.domain.com";
if(args.length == 3) {
username = args[0];
password = args[1];
host = args[2];
}
Session session = Session.getInstance(new Properties(), null);
MimeMessage message = new MimeMessage(session);
InternetAddress from = new InternetAddress(""Java Duke"@"+ host);
InternetAddress to = new InternetAddress(""Java Duke"@"+ host);
message.setFrom(from);
message.addRecipient(Message.RecipientType.TO, to);
message.setSubject("This message is just added");
message.setText("Welcome Duke");


Store store = session.getStore("imap");
store.connect(host, username, password);

Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
folder.appendMessages(new Message[] {message});


Message messages[] = folder.getMessages();
for (int i=0, n=messages.length; i System.out.println(i + ": " + messages[i].getFrom()[0] + " " + messages[i].getSubject());
}
}
}

The output and command is as follows

>java TestMail1 "Chandra Patni" welcome1 localhost
0: Chandra Patni <"Chandra Patni"@localhost> test
1: <"Java Duke"@localhost> This message is just added
2: <"Java Duke"@localhost> This message is just added
3: <"Java Duke"@localhost> This message is just added
About | Sitemap | Contact