aspose file tools*
The moose likes Servlets and the fly likes Sent email source code but no from display in outlook express!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Sent email source code but no from display in outlook express!!" Watch "Sent email source code but no from display in outlook express!!" New topic
Author

Sent email source code but no from display in outlook express!!

Eric Wang
Greenhorn

Joined: Dec 21, 2000
Posts: 22
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());
}
%>
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
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
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
Mike Troxclaire
Greenhorn

Joined: Sep 01, 2004
Posts: 11
Hello Eric,

Try to delete the < & > from your From: part. See if that works.

Mike.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sent email source code but no from display in outlook express!!
 
Similar Threads
how to send a mail from a jsp?
Email with jsp
help with SMTP CC
Email in jsp
Tomcat and email