当前位置: 代码迷 >> Java Web开发 >> javamail的问题[求助]好奇怪哦
  详细解决方案

javamail的问题[求助]好奇怪哦

热度:339   发布时间:2007-04-02 12:32:53.0
javamail的问题[求助]好奇怪哦

请大家帮忙看哈,

错在那里 我用的是tomcat
当写到/*(红色)的时候还是对的,,下去一行写

Mimemassage the Message = new MimeMessage(theSession);

这时候就错了,提示:

The server encountered an internal error () that prevented it from fulfilling this request.


难道是怪mail.jar没配置好吗?也不应该啊,Session都能用啊,请大家帮忙啊 都快哭了


<%@page contentType="text/html"%>
<%@page pageEncoding = "GB2312"%>
<%@page import = "java.util.*,java.io.*"%>
<%@page import = "javax.mail.*"%>

<%@page import = "javax.mail.internet.*"%>
<%@page import = "javax.activation.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> mail </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<%
Properties theProperties = System.getProperties();
theProperties.put("mail.host","127.0.0.1");
theProperties.put("mail.transport.protocol","smtp");

out.println("234234tTGSDG5");
Session theSession =
Session.getDefaultInstance(theProperties,null);
theSession.setDebug(false);


MimeMessage theMessage = new MimeMessage(theSession);/*
theMessage.setFrom(new InternetAddress("coffee@fj.com"));/*

theMessage.setRecipients(Message.RecipientType.TO,"35033734@qq.com");
theMessage.setSubject("JavaMail");
theMessage.setText("看哈通了没有","GB2312");

Transport.send(theMessage);
out.println("发送成功");*/


%>
daodidf
</BODY>
</HTML>



[此贴子已经被作者于2007-4-2 12:55:57编辑过]

搜索更多相关主题的帖子: javamail  The  target  page  

----------------解决方案--------------------------------------------------------
大家一定要帮我啊,,我代表我自己谢谢你们了先
----------------解决方案--------------------------------------------------------
真的没有人肯帮忙解决一下吗?








----------------解决方案--------------------------------------------------------
不是说了第34行有异常吗
你检查一下吧
----------------解决方案--------------------------------------------------------
建议你在JAVA中去写一个来用debug调试,用JSP太难调试了。
----------------解决方案--------------------------------------------------------

楼主,其实呢,很多问题还是靠自己的。
其实你完全可以自己搞定n多东西。靠自己才是硬道理。

javamail使用笔记
本文描述了3个常见的javamail问题,至于其它问题可以看javamail的例子
1:怎样发送认证邮件

不想以前那样,很多smtp服务器已经不能随便让你通过它发信,你必须提供用户名和密码才能发信,下面的示例演示了这样的一种情况。


import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class MailExample {
public static void main (String args[]) throws Exception ,MessagingException{
String host = "smtp.263.net";
String from = "zong_feng@263.net";
String to = "zfvc@163.com";


// Get system properties
Properties props = System.getProperties();

// Setup mail server
props.put("mail.smtp.host", host);

props.put("mail.smtp.auth","true");

// Get session
Session session = Session.getDefaultInstance(props, null);

// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");
message.saveChanges();

// Send message
Transport transport = session.getTransport("smtp");
transport.connect(host, "zong_feng","111111");
transport.sendMessage(message, message.getAllRecipients());
}
}


2:发送附件

import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class sendfile {

public static void main(String[] args) {


String to = "zfvc@163.com";
String from = "zong_feng@263.net";
String host = "smtp.263.net";
String filename = args[0];
//boolean debug = Boolean.valueOf(args[4]).booleanValue();
String msgText1 = "宗锋.n";
String subject = "Sending a file";

// create some properties and get the default Session
Properties props = System.getProperties();
props.put("mail.smtp.host", host);

props.put("mail.smtp.auth","true");

Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);

try {
// create a message
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);

// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(msgText1);

// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();

// attach the file to the message
FileDataSource fds = new FileDataSource(filename);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());

// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);

// add the Multipart to the message
msg.setContent(mp);

// set the Date: header
msg.setSentDate(new Date());

// send the message

Transport transport = session.getTransport("smtp");
transport.connect(host, "zong_feng","dsf");
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
} catch (MessagingException mex) {
mex.printStackTrace();
Exception ex = null;
if ((ex = mex.getNextException()) != null) {
ex.printStackTrace();
}
}
}
}


3:怎样是IMAP和POP3一起工作

Use different session objects (don't use the default). Get the session with Session.getInstance() instead of getDefaultInstance().


----------------解决方案--------------------------------------------------------
我也是从网上找的,我相信你也可以,多动手,主动一点。很多问题也就不成为问题了,说明下,上面的文章是转的,偶可是从来不冒充原创嘀

----------------解决方案--------------------------------------------------------