JSP发送邮件实例

2016-01-29 12:04 14 1 收藏

JSP发送邮件实例,JSP发送邮件实例

【 tulaoshi.com - Java 】

  vishal_donth gave this response on 10/18/2000:  
//these are the pakages to be imported from  
// Java Mail  
//The Java Mail PAckage either be dowloaded  
//seperately  
//or else is Available in the J2sdkee1.2  
// (Java Enterprise Edition)  

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


//This function can be used to send the mail  
// with the parameters given to it  
//U have to specify the smtp server through  
//which u have to send the mail  
//since i was trying with a homenetmail  
//account i directly sent the mail its server  
//For sending this mail u need a mail server  
//which lets u to relay the messages  
//Try this thing for sending to a  
//www.homenetmail.com account because it lets  
//u send  
//mails to the accounts like example try  
//sending it to a "abc@homenetmail.com"  
//account.Create the mail account in homenet  
//mail first. If u get any other server which  
//supports relaying u can try this on that  
//also.  

//Use this function in ur Servlet to send  
//mail by calling the function with the  
//parameters  

public void sendMail(String toAddr, String subject, String body, String fromAddr)throws RemoteException{  
try{  
Properties props = new Properties();  
props.put("mail.smtp.host","mail.homenetmail.com");  
//Here we specify the SMTP server through  
//which the mail should be delivered  
Session session = Session.getDefaultInstance(props, null);  
Message msg = new MimeMessage(session);  
msg.setFrom(new InternetAddress(fromAddr));  
//Specify the From Address  
InternetAddress[] tos =InternetAddress.parse(toAddr);  
//Specify the To Address  
msg.setRecipients(Message.RecipientType.TO,tos);  
msg.setSubject(subject);  
//Specify the Subject  
msg.setText(body);  
//Specify the Body  
Transport.send(msg);  
System.out.println("Message is Sent");  
}  
catch(Exception e){  
System.out.println(e);  
}  
}  

// U have to run this function on a computer  
//which is directly connected  
// to internet but not through a  
//proxy......or else use a proxy which  
//supports SMTP  
 

来源:https://www.tulaoshi.com/n/20160129/1484481.html

延伸阅读
标签: PHP
  test_smtp.php <? require("smtp.php"); $smtp=new smtp_class; $smtp-host_name="mail.xiaocui.com"; $smtp-localhost="localhost"; $from="webmaster@xiaocui.com"; $to="root@xiaocui.com"; if($smtp-SendMessage(   $from,   array(   &nbs...
标签: PHP
  作者:Kartic Krishnamurthy 译者:limodou 已经厌倦了给你的朋友和客户发送那些单调乏味的文本通知和信件了吗?曾经考虑过发送附件或在邮中 嵌入HTML吧。 答案就是MIME。接下来的几页解释了MIME的基础知识,创建符合MIME的信息,然后用一个可以工作的PHP 类结束,这个类实现了发送符合MIME邮件。注意对调用脚本,调用者等...
标签: Java JAVA基础
  SimpleSendMessage.java import java.util.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; public class SimpleSendMessage { public static void main(String[] args) { // Collect the necessary information to send a simple message // Make sure to replace the values for host, to, a...
如何设置Foxmail定时发送邮件   1、首先在收信箱找到需要发送的联系人,或者是直接点击上面的写邮件直接收入要发送的联系人的邮箱地址。 2、在弹出的写邮件窗口的左上角找到如图所示的小方格!并点击,在下拉菜单中,有个定时发送按钮,点击进去。 3、进入定时发送主界面以后,选择需要发送邮件的时间,最...
标签: ASP
  前一段时间有发过一个简单的JMAIL邮件发邮件的代码,今天就把这个代码做一个具体的注解,并增加了另外两个格式的代码,并举几个简单的例子: 首先是jmail.smtpmail的核心代码: <%   Set jmail = Server.CreateObject("JMAIL.SMTPMail")   '创建一个JMAIL对象   jmail.silent = true   'JMAIL不...

经验教程

487

收藏

81

精华推荐

超级简单的发送邮件程序

超级简单的发送邮件程序

东少丶天平

用PHP发送MIME邮件(四)

用PHP发送MIME邮件(四)

bdfk901a

用PHP发送MIME邮件(五)

用PHP发送MIME邮件(五)

救赎愜红颜归去

微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部