javax.mail发送邮件jsp页面

1 篇文章 0 订阅
1 篇文章 0 订阅
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.*"%>
<%@page import="javax.mail.*"%>
<%@page import="javax.mail.internet.*"%>
<%@page import="javax.activation.*"%>

<%
    
    /*
    sina.com: 
    POP3服务器地址:pop3.sina.com.cn(端口:110)
    SMTP服务器地址:smtp.sina.com.cn(端口:25) 
    
    163.com: 
    POP3服务器地址:pop.163.com(端口:110)
    SMTP服务器地址:smtp.163.com(端口:25)
    */
    
    String recipient="000@qq.com";
    String sender="aaa@sina.com";
    String subject="hello";
    String text="hello, this is my first jsp mail!";
    
    String host="smtp.sina.com.cn";
    String username="aaa@sina.com";
    String password="000";
    
    Properties props=new Properties();
    
    props.put("mail.smtp.host",host);
    props.put("mail.smtp.port","25");
    props.put("mail.smtp.auth","true");
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); 
    
    Session mailsession=Session.getDefaultInstance(props);
    boolean sessionDebug=false;
    mailsession.setDebug(sessionDebug);
    
    MimeMessage message=new MimeMessage(mailsession);
    
    message.setFrom(new InternetAddress(sender));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient));
    message.setSubject(subject, "UTF-8");
    message.setText(text);
    message.saveChanges();
    
    Transport transport=mailsession.getTransport("smtp");
    transport.connect(host, username, password);
    transport.sendMessage(message, message.getAllRecipients());
    transport.close();    

%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>sendmail</title>
    </head>
    <body>
        <h1>邮件已经发送!</h1>
    </body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值