Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Eric Wang
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Eric,

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

Mike.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic