• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());
}
%>
 
author
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Eric,

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

Mike.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic