This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

HOWTO native Windows unicode UTF8 encoded email via SMTP


Phew!

with a bit of help, I've finally pieced together how to build a native
windows app that does the above.

This is just a quick writeup after I've tested the program a couple of
times. More details/clarifications available on demand.

First there are are some bugs/tripwires in GCC that need to be
traversed:

- When compiling .jar's there might be files that exist in the class
path within the jar that are not available after compilation. GCC does
not automatically make available these files, nor does it warn about
them. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12894
- Compiling a .java file and a .class file can have different results.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12908
- Sometimes it is necessary to add explicit references to classes 
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12908
- inetlib.jar does not compile. Remove the ftp classes.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12893
- beware of codepage issues when compiling .java files w/GCJ
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12907

Enough of that. Now for the instructions:

- Fetch the various .jar files from GNU Classpathx CVS.
- Compile latest GNU Classpathx/mail from CVS => more .jars
The only trick here, is to use Linux and not CygWin(some error message
or other) to:

./configure
make

- Compile the app using latest GCC 3.4.

\wingcc\bin\gcj -c -o javax-security.o javax-security.jar
\wingcc\bin\gcj -c --classpath jsse.jar;javax-security.jar -o inetlib.o
inetlib.jar
\wingcc\bin\gcj -c --classpath inetlib.jar;activation.jar -o gnumail.o
gnumail.j
ar
\wingcc\bin\gcj -c -o activation.o activation.jar 
\wingcc\bin\gcj -c --classpath gnumail.jar;inetlib.jar -o smtp.o
smtp.jar
# Notice that I have Norwegian letters in my test program, and I haven't
# toyed with the 
\wingcc\bin\gcj --classpath gnumail.jar -c -o send.o Send.class
\wingcc\bin\gcj -c -o jsse.o jsse.jar
\wingcc\bin\gcj --main=Send -o send activation.o gnumail.o inetlib.o
javax-security.o send.o smtp.o jsse.o Dummy.java

- Send.java was compiled w/Eclipse. GCJ can probably compile it too, but
I wasn't interested in dealing with the GCJ --encoding option at this
point. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12907
- The Dummy.java file is just to avoid problems with various classes
dropping out of the link. Note that it *must* be compiled w/.java and
*not* .class
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12908

- Before running, we must make various files that used to be in the
classpath inside the .jars available again in the classpath. Simplest is
just to unzip them in the same directory as the resulting send.exe ends
up in.

unzip gnumail.jar META-INF/*
unzip smtp.jar META-INF/*

Finally the code itself:


import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class Send
{

	public static void main(String[] args)
	{
		System.out.println("hello world");
		try
		{
			/** Set up session props and session. */
			Properties sessionProps = System.getProperties();
			String m_host="mail.broadpark.no";
			sessionProps.put("mail.smtp.host", m_host);
			Session m_session = Session.getDefaultInstance(sessionProps);
			MimeMessage message = new MimeMessage(m_session);
			String from="oyvind.harboe@zylin.com";
			message.setFrom(new InternetAddress(from));
		//	message.setAllow8bitMIME(true);
			/** to is an array of type InternetAddress. */
			
			String to="oharboe@broadpark.no";
			message.addRecipients(Message.RecipientType.TO, to);
						
			String str1="Ãyvind spiser Ãl";
			String str2=" some Japaneese text ";
			
			str2+=(char)0x79C1;
			str2+=(char)0x306B;
			str2+=(char)0x30D3;str2+=(char)0x30FC;str2+=(char)0x30EB;str2+=(char)0x304C;str2+=(char)0x3042;str2+=(char)0x3063;str2+=(char)0x3066;str2+=(char)0x3082;str2+=(char)0x3088;str2+=(char)0x3044;str2+=(char)0x304B;
			
			String str3="simplesubject";
			 
			System.out.println("Subject: " + str2);
			
			message.setSubject(str1+ " " + str2, "UTF8");
			
			message.setText(str1+ " " + str2, "UTF8");
			Transport transport =  m_session.getTransport("smtp");
			transport.connect(m_host, "", "");
			transport.sendMessage(message, message.getAllRecipients());
			transport.close();
		}
		catch (AddressException e)
		{
			e.printStackTrace();
		}
		catch (NoSuchProviderException e)
		{
			e.printStackTrace();
		}
		catch (MessagingException e)
		{
			e.printStackTrace();
		}
	}
}


public class Dummy
{
	private static Class c1 = gnu.gcj.convert.Input_UTF8.class;
	private static Class c2 = gnu.gcj.convert.Output_UTF8.class;
	private static Class c3 =gnu.gcj.convert.Input_ASCII.class;
	private static Class c4 =gnu.gcj.convert.Output_ASCII.class;
}











Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]