简体   繁体   English

获取问题com.sun.mail.smtp.SMTPSendFailedException:530 5.7.0必须首先发出STARTTLS命令。 dg12sm142339333pac.47 - gsmtp

[英]Getting Issue com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. dg12sm142339333pac.47 - gsmtp

i am trying to send a mail using java mail api using the below code but getting some error(530 5.7.0 Must issue a STARTTLS command first. v2sm21182861pfi.93 - gsmtp) ,Please any one help me to run below code thanks in advance. 我正在尝试使用以下代码使用java mail api发送邮件但是收到一些错误(530 5.7.0必须首先发出STARTTLS命令.v2sm21182861pfi.93 - gsmtp),请任何人帮我运行下面的代码,提前感谢。

CODE

import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

public class SendMailTest {

public static boolean sendHTMLMail() {
    String msg, String[] to
    final String from = "*****@gmail.com";
    final String password = "****";
    String senderName = "some Name";
    String sub = "Some Subject";
    String msg = "testing mail";
    String[] to = new String[1];
    to[0] = "***@gmail.com";

    String host = "smtp.gmail.com";
    MimeMultipart multipart = new MimeMultipart();
    MimeBodyPart bodypart = new MimeBodyPart();

    Properties props = new Properties();
    props.put("mail.smtp.starttls.enable", "true");
    props.setProperty("mail.smtp.host", host);
    props.put("mail.smtp.port", 587);
    props.put("mail.smtp.auth", "true");
    mail.setTLS(true);
    try {
        Session session = Session.getInstance(props, new javax.mail.Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(from, password);
            }
        });
        Transport transport = session.getTransport("smtp");

        Message mimeMessage = new MimeMessage(session);
        mimeMessage.setFrom(new InternetAddress("" + senderName + "<" + from + ">"));

        InternetAddress[] toAddress = new InternetAddress[to.length];
        for (int i = 0; i < to.length; i++) {
            toAddress[i] = new InternetAddress(to[i]);
        }

        for (InternetAddress toAddres : toAddress) {
            mimeMessage.addRecipient(Message.RecipientType.TO, toAddres);
        }


        bodypart.setContent(msg, "text/html; charset=\"utf-8\"");
        multipart.addBodyPart(bodypart);

        mimeMessage.setSubject(sub);
        mimeMessage.setContent(multipart);

        transport.connect(from, password);
        transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
        transport.close();
        return true;
    } catch (MessagingException me) {
        me.printStackTrace();
    }
    return false;
}

Error 错误

DEBUG: loading new provider protocol=aws, className=com.amazonaws.services.simpleemail.AWSJavaMailTransport, vendor=Amazon Web Services LLC, version=null
DEBUG: loading new provider protocol=imap, className=com.sun.mail.imap.IMAPStore, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=imaps, className=com.sun.mail.imap.IMAPSSLStore, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=smtp, className=com.sun.mail.smtp.SMTPTransport, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=smtps, className=com.sun.mail.smtp.SMTPSSLTransport, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=pop3, className=com.sun.mail.pop3.POP3Store, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=pop3s, className=com.sun.mail.pop3.POP3SSLStore, vendor=Sun Microsystems, Inc, version=null
DEBUG: getProvider() returning provider protocol=smtp; type=javax.mail.Provider$Type@156c039; class=com.sun.mail.smtp.SMTPTransport; vendor=Sun Microsystems, Inc
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 25, isSSL false
220 smtp.gmail.com ESMTP v2sm21182861pfi.93 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 25

EHLO lenovo-PC
250-smtp.gmail.com at your service, [117.197.6.49]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
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 "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<xyz@gmail.com>
530 5.7.0 Must issue a STARTTLS command first. v2sm21182861pfi.93 - gsmtp
DEBUG SMTP: got response code 530, with response: 530 5.7.0 Must issue a STARTTLS command first. v2sm21182861pfi.93 - gsmtp

RSET
250 2.1.5 Flushed v2sm21182861pfi.93 - gsmtp
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. v2sm21182861pfi.93 - gsmtp

com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. v2sm21182861pfi.93 - gsmtp

As per Using Javamail to connect to Gmail smtp server ignores specified port and tries to use 25 根据使用Javamail连接到Gmail smtp服务器忽略指定的端口并尝试使用25

You probably need to use "smtps" for the protocol (and in every property), and not "smtp", and use the smtps port number (587) as a string(!), not the smtp one as a number. 您可能需要为协议(以及每个属性)使用“smtps”,而不是“smtp”,并使用smtps端口号(587)作为字符串(!),而不是smtp作为数字。

(Yeah, I would expect it to be be intelligent about it when you enable starttls...) (是的,当你启用starttls时,我希望它是聪明的...)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 com.sun.mail.smtp.SMTPSendFailedException:530 5.7.0必须首先发出STARTTLS命令 - com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first 我得到 530 5.7.0 必须先发出 STARTTLS 命令。 a5sm29349940pbw.4 - 从java程序发送邮件时gsmtp错误,如何解决? - i am getting 530 5.7.0 Must issue a STARTTLS command first. a5sm29349940pbw.4 - gsmtp error while send a mail from java program, how to solve it? com.sun.mail.smtp.SMTPSendFailedException:530 5.7.1客户端未通过身份验证 - com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Client was not authenticated 接收到Java邮件api和hmailserver:530 5.7.0必须首先发出STARTTLS命令 - Java mail api and hmailserver RECEIVED: 530 5.7.0 Must issue a STARTTLS command first com.sun.mail.smtp.SMTPSendFailedException Javamail - com.sun.mail.smtp.SMTPSendFailedException Javamail com.sun.mail.smtp.SMTPSendFailedException:530-5.5.1需要身份验证(Java Mail) - com.sun.mail.smtp.SMTPSendFailedException: 530-5.5.1 Authentication Required (Java Mail) com.sun.mail.smtp.SMTPSendFailedException: 530-5.5.1 需要身份验证 - com.sun.mail.smtp.SMTPSendFailedException: 530-5.5.1 Authentication Required 必须首先发出STARTTLS命令。 -gsmtp; 使用Gmail帐户发送带有附件的电子邮件 - Must issue a STARTTLS command first. - gsmtp ; Sending email with attachment using gmail account 必须首先发出STARTTLS命令。 mail.smtp.EnableSSL.enable已设置为true - Must issue a STARTTLS command first. mail.smtp.EnableSSL.enable already set to true MailSendException:失败的消息:com.sun.mail.smtp.SMTPSendFailedException - MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM