This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Hi, All: This is a perfect code can sent out your email, but when I read my mail in the outlook express, nothing display under the from, what happen to it? But I use another SMTP server, it will work, How Come? Can anyone help? <html> <body bgcolor="white"> <font size=5 color="black"> <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <%@ page import="sun.net.smtp.SmtpClient.*" %> <%@ page import="javax.mail.*" %> <%@ page import="javax.mail.event.*" %> <%@ page import="javax.mail.internet.*" %> <% try { String to="homeway@anycompany.com"; String nameit="ERIC"; String subject="A Christmas E-Card From Hongwei"; String from="From: <hongwei@anycompany.com>"; String msgbody="IT IS GOOD TO LEARN NEW THINGS"; String servername="anycompany.com"; //Session session1 = session; //Message msg = new MimeMessage(session1); sun.net.smtp.SmtpClient sm = new sun.net.smtp.SmtpClient (servername); sm.from(from); sm.to(to); PrintStream msg=sm.startMessage(); msg.println("To: Hongwei Merry Christmas!!!"); msg.println("Subject: A E-Card from Hongwei"); //msg.println(from); msg.println(subject); //msg.println(to); msg.println(); msg.println(msgbody); msg.println("========Hong Wei=============="); sm.closeServer(); out.println("Your mail has been sent!"); out.println(to); } catch(Exception e) { out.println("The error message i am getting is:"); out.println(e.getMessage()); } %>
Try flushing the output before you close the mail connection like so:
It's also a good idea to put the close statemants in a finally block to ensure that they get closed not matter what happens. This might do the trick. Otherwise, try setting the context type to "text/plain". Hope this helps Sean
Eric Wang
Greenhorn
Joined: Dec 21, 2000
Posts: 22
posted
0
Hello Sean MacLean: Happy new year to you first. And thank you very much for the coding. I have try it out, but the problem is still there, I don't know what is wrong with that, hope some one can help me out this problem. Eric