本文介绍了为什么GMail接受没有验证的邮件发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public class SendMail {
private class SMTPAuthenticator extends javax.mail.Authenticator
{
@Override
public PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(userID,pwd);
$ b $ public void sendMail()抛出异常{
String strFromIds [email protected];
字符串strToIds [email protected];
String strSubject =示例邮件主题。;
String strContent =邮件内容示例;
属性objProperties = System.getProperties();
objProperties.put(mail.smtp.host,< smtp主机名称>);
objProperties.put(mail.smtp.port,25);
objProperties.put(mail.transport.protocol,smtp);
objProperties.put(mail.smtp.submitter,< user id>);
objProperties.put(mail.smtp.auth,true);
objProperties.put(mail.debug,true);
Session objSMTPSession = Session.getDefaultInstance(objProperties,new
SMTPAuthenticator());
消息objMessage = new MimeMessage(objSMTPSession);
objMessage.setFrom(new InternetAddress(strFromIds));
InternetAddress [] objToAddress = new InternetAddress [1];
objToAddress [0] =新的InternetAddress(strToIds);
objMessage.setRecipients(Message.RecipientType.TO,objToAddress);
objMessage.setSubject(strSubject);
Multipart objMultiPart = new MimeMultipart();
MimeBodyPart objBodyPart = new MimeBodyPart();
objBodyPart.setText(strContent);
objMultiPart.addBodyPart(objBodyPart);
objMessage.setContent(objMultiPart);
日期objSentDate = new Date();
objMessage.setSentDate(objSentDate);
Transport.send(objMessage);
objMessage = null;
public static void main(String [] args){
try {
new SendMail()。sendMail();
} catch(Exception ex){
System.out.println(main ::+ ex中的异常);
}
}
}
通过使用上面的代码,
我可以使用GMail邮件标识的发件人地址(例如:[email protected])向gmail用户发送邮件>这里我给了我的smtp(公司邮件服务器)服务器主机名,以及我公司邮件服务器的userid和pwd(这是作为smtp主机提供的)...
有了这些,我以GMail用户的身份发送邮件,但是为什么GMAIL正在接受这种类型的邮件。
h2_lin>解决方案你已经发现了为什么有垃圾邮件。 : - )
您通过公司的邮件服务器发送邮件。您公司的邮件服务器似乎没有检查您使用的发件人地址是否对您的邮件服务器有效,因此它使您可以使用您的Gmail地址而不是公司地址。不,它不会检查Gmail以确定它是否正常。
public class SendMail {
private class SMTPAuthenticator extends javax.mail.Authenticator
{
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("userID", "pwd");
}
}
public void sendMail() throws Exception {
String strFromIds = "[email protected]";
String strToIds = "[email protected]";
String strSubject = "Sample Mail Subject.";
String strContent = "Sample Mail Content";
Properties objProperties = System.getProperties();
objProperties.put("mail.smtp.host", "<smtp host name>");
objProperties.put("mail.smtp.port", "25");
objProperties.put("mail.transport.protocol", "smtp");
objProperties.put("mail.smtp.submitter", "<user id>");
objProperties.put("mail.smtp.auth", true);
objProperties.put("mail.debug", "true");
Session objSMTPSession = Session.getDefaultInstance(objProperties, new
SMTPAuthenticator());
Message objMessage = new MimeMessage(objSMTPSession);
objMessage.setFrom(new InternetAddress(strFromIds));
InternetAddress[] objToAddress = new InternetAddress[1];
objToAddress[0] = new InternetAddress(strToIds);
objMessage.setRecipients(Message.RecipientType.TO, objToAddress);
objMessage.setSubject(strSubject);
Multipart objMultiPart = new MimeMultipart();
MimeBodyPart objBodyPart = new MimeBodyPart();
objBodyPart.setText(strContent);
objMultiPart.addBodyPart(objBodyPart);
objMessage.setContent(objMultiPart);
Date objSentDate = new Date();
objMessage.setSentDate(objSentDate);
Transport.send(objMessage);
objMessage = null;
}
public static void main(String[] args) {
try {
new SendMail().sendMail();
} catch (Exception ex) {
System.out.println("Exception in main :: " + ex);
}
}
}
By using the above code,i am able to send a mail to gmail user with the from address of GMail mail id(eg:[email protected]), without giving authentication details of gmail id,
here i gave my smtp ( company mail server ) server host name, and userid and pwd of my company mail server( which is given as smtp host)...
With these, i am sending mail as GMail user,,
But why GMAIL is accepting this type of mails.
解决方案
You've discovered why there is spam. :-)
You're sending the message through your company's mail server. Your company's mail server doesn't appear to be checking whether the From address you use is valid for your mail server, so it's letting you use your Gmail address instead of your company address. No, it doesn't check with Gmail to find out if it's ok.
这篇关于为什么GMail接受没有验证的邮件发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!