Azure SMTP 身份验证失败

问题描述 投票:0回答:1

我已按照快速入门:如何创建使用 SMTP 发送电子邮件的身份验证凭据

中的步骤进行操作
  • 创建了一项名为“外发邮件”的服务
  • 注册了一个应用程序
  • 创建了一个具有上述服务和权限范围的角色
    • Microsoft.Communication/CommunicationServices/阅读
    • Microsoft.Communication/电子邮件服务/写入
    • (确定给了 Microsoft.Communication 的其余部分)
  • 将角色分配给应用程序
  • 创建了客户秘密
  • 连接用户名

我尝试发送电子邮件,但身份验证不起作用。我试过:

  • 不同的客户=>没有区别
  • 设置mail.smtp.auth.mechanisms =>默认的LOGIN似乎是正确的,其他返回不支持

代码:

package com.zenmo

import jakarta.mail.Authenticator
import jakarta.mail.PasswordAuthentication
import jakarta.mail.*
import java.util.*


fun main() {
    val prop: Properties = Properties()
    prop.put("mail.smtp.auth", true)
    prop.put("mail.smtp.starttls.enable", "true")
    prop.put("mail.smtp.host", "smtp.azurecomm.net")
    prop.put("mail.smtp.port", "587")
    prop.put("mail.smtp.ssl.trust", "smtp.azurecomm.net")

    val session = Session.getInstance(prop, object : Authenticator() {
        override fun getPasswordAuthentication() = PasswordAuthentication(
            "outgoing-mail.c8d8ffe4-1ff2-4b5b-a6e5-391eac5e1238.1d9c9a28-bfa5-49e1-b0b5-08e4041f77b1",
            "R4S***************************"
        )
    })
    session.debug = true

    val smtpTransport = session.getTransport("smtp")
    smtpTransport.connect()
    smtpTransport.close()
}

调试输出:

DEBUG: setDebug: Jakarta Mail version 2.1.1
DEBUG: getProvider() returning jakarta.mail.Provider[TRANSPORT,smtp,org.eclipse.angus.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: protocolConnect returning false, host=smtp.azurecomm.net, user=erik, password=<null>
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.azurecomm.net", port 587, isSSL false
220 ic3-transport-smtp-acs-deployment-54b7c4d9cd-m6ghd Microsoft ESMTP MAIL Service ready at Fri, 26 Jan 2024 15:15:55 +0000 (08DBFCDFC373B98E)
DEBUG SMTP: connected to host "smtp.azurecomm.net", port: 587
EHLO legion5pro
250-ic3-transport-smtp-acs-deployment-54b7c4d9cd-m6ghd Hello [89.255.15.206]
250-SIZE 10485760
250 STARTTLS
DEBUG SMTP: Found extension "SIZE", arg "10485760"
DEBUG SMTP: Found extension "STARTTLS", arg ""
STARTTLS
220 2.0.0 SMTP server ready
EHLO legion5pro
250-ic3-transport-smtp-acs-deployment-54b7c4d9cd-m6ghd Hello [89.255.15.206]
250-SIZE 10485760
250 AUTH LOGIN
DEBUG SMTP: Found extension "SIZE", arg "10485760"
DEBUG SMTP: Found extension "AUTH", arg "LOGIN"
DEBUG SMTP: protocolConnect login, host=smtp.azurecomm.net, user=outgoing-mail.c8d8ffe4-1ff2-4b5b-a6e5-391eac5e1238.1d9c9a28-bfa5-49e1-b0b5-08e4041f77b1, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2 
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed
azure kotlin smtp azure-communication-services
1个回答
0
投票

问题是我没有创建 Azure 通信服务资源,仅创建了 Azure 通信电子邮件资源。

© www.soinside.com 2019 - 2024. All rights reserved.