使用javamail发送SMTP验证邮件

本文介绍如何使用JavaMail 1.4通过SMTP进行邮件发送,并提供了一个验证类的示例。在实际操作中,作者在smtp.126.com上成功测试了邮件发送,但在smtp.tom.com遇到问题,尽管显示发送成功,但收不到邮件,可能是SMTP服务器配置导致的。
摘要由CSDN通过智能技术生成

现在很多邮件服务器都需要进行验证,本文使用javamail1.4使用需要验证的smtp 发送邮件,作者使用smtp.126.com测试成功,但使用smtp.tom.com提示发送成功,但总接受不到,可能根对方smtp有关系

验证类:

package  com.test.auth;

import  javax.mail.Authenticator;
import  javax.mail.PasswordAuthentication;

public   class  Authentic  extends  Authenticator  {
    
protected PasswordAuthentication getPasswordAuthentication() {
          String username 
= "1111";    //大多数是你邮件@前面的部分
          String pwd = "22222";
          
return new PasswordAuthentication(username, pwd);
         }


}

 

发送页面:其中from中的邮箱地址要和验证类中设置的用户名、密码统一起来

<% @ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding
="GB18030"
%>
<! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >
< html >
< head >
< meta 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值