我使用JavaMail;我无法发送电子邮件,我已经使用验证试过了,还是没有,但它不工作。 有人可以帮忙吗?使用JavaMail
private boolean InitMailer(String sSMPTGateWay)
{
try
{
oProps=new Properties();
oProps.put("mail.smtp.host",sSMPTGateWay);
//oProps.put("mail.smtp.socketFactory.port", "465");
//oProps.put("mail.smtp.port", "465");
oProps.put("mail.smtp.starttls.enable", "true");
// oProps.put("mail.smtp.socketFactory.class",
// "javax.net.ssl.SSLSocketFactory");
oProps.put("mail.smtp.auth", "true");
//oProps.put("mail.smtp.port", "465");
Authenticator auth = new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("[email protected]","mypassword");
}
};
oSession=Session.getInstance(oProps,auth);
oSession.setDebug(true);
oTransport=oSession.getTransport(oSession.getProvider("smtp"));
System.out.println("tento di connettermi");
oTransport.connect();
System.out.println("connesso?");
if(!oTransport.isConnected())
{
ErrorLog.warningLog("MService: MService(): Mail Server "+sMailGateWay+" non operativo. Tento un altro Gateway.");
return false;
}
}
catch(Exception e)
{
e.printStackTrace();
ErrorLog.warningLog("MService: MService(): Mail Server "+sMailGateWay+" non operativo. Tento un altro Gateway.");
return false;
}
return true;
}
private void sendMessage(String sFrom,String sTo,String sSubject,String sBody) throws Exception
{
if(Constants.ENABLE_MAIL_SERVICE.equals("NO"))
{
ErrorLog.warningLog("Tentativo di invio, Mail disabilitata: \n From:"+sFrom+"\n To:"+ sTo +"\n Subject: "+sSubject + "\n Body:\n"+sBody);
return;
}
if(Constants.ENABLE_MAIL_SERVICE.equals("TEST"))
sTo=Constants.TEST_MAIL;
MimeMessage msg=new MimeMessage(oSession);
msg.setFrom(new InternetAddress(sFrom));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress(sTo));
msg.setSubject(sSubject,"iso-8859-1");
msg.setSentDate(new Date());
msg.setText(sBody,"iso-8859-1");
System.out.println("mando mex");
oTransport.send(msg);
}
,这是错误,那么这是不是一个错误,但邮件没有发送
220 smtp.gmail.com ESMTP q4sm9246160wjk.24 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 25
EHLO Michele
250-smtp.gmail.com at your service, [79.36.174.226]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
connesso?
NOOP
250 2.0.0 OK q4sm9246160wjk.24 - gsmtp
new MSERVICE
[email protected]
Sending from ([email protected]) to ([email protected]) subject (Registrazione Star Cinema) html(false).
mando mex1
mando mex
NOOP
250 2.0.0 OK q4sm9246160wjk.24 - gsmtp