使用Outlook smtp服务器发送ics文件RSVP格式不能正常工作吗?

时间:2018-11-21 08:52:38

标签: email kotlin outlook javamail icalendar

我有一个代码,可以在通过我的个人凭据使用gmail smtp服务器时很好地工作:

fun sendEventInvitation(from: Profile, to: Profile, meetup: Meetup) {
    val message: MimeMessage = emailSender.createMimeMessage()

    message.setFrom(InternetAddress("foo1@foo1.com"))
    message.setRecipient(Message.RecipientType.TO, InternetAddress("foo2@foo2.com"))
    message.subject = "foo"

    val messageBodyEvent = MimeBodyPart()
    val id = UUID.randomUUID().toString()
    val eventIcs = formatCalendarFile(id, from, to, meetup)
    messageBodyEvent.dataHandler = DataHandler(ByteArrayDataSource(eventIcs, "text/calendar; charset=\"utf-8\"; method=REQUEST"))
    messageBodyEvent.setHeader("Content-Transfer-Encoding", "base64")

    val multiPart = MimeMultipart()
    multiPart.addBodyPart(messageBodyEvent)

    message.setContent(multiPart)

    emailSender.send(message)
}

eventIcs基本上是iCal正确格式的String

但是每当我使用公司的凭据切换到Outlook服务器时,就会出现以下错误:

554 5.2.0 STOREDRV.Submission.Exception:InvalidRecipientsException; Failed to process message due to a permanent exception with message A message can't be sent because it contains no recipients. InvalidRecipientsException: A message can't be sent because it contains no recipients. [Hostname=AM6PR01MB5011.eurprd01.prod.exchangelabs.com]
DEBUG SMTP: got response code 554, with response: 554 5.2.0 STOREDRV.Submission.Exception:InvalidRecipientsException; Failed to process message due to a permanent exception with message A message can't be sent because it contains no recipients. InvalidRecipientsException: A message can't be sent because it contains no recipients. [Hostname=AM6PR01MB5011.eurprd01.prod.exchangelabs.com]

现在,很奇怪,当我删除method=REQUEST附件标头时:

messageBodyEvent.dataHandler = DataHandler(ByteArrayDataSource(eventIcs, "text/calendar; charset=\"utf-8\"))

它可以工作,但是由于没有此标头,因此Outlook客户端无法很好地识别ICS,并且无法按照here的说明向收件人显示RSVP选项。

我尝试使用相同的凭据从Thunderbird发送邀请,并且该邀请有效。因此,它根本不链接到规则。

这是完整的调试输出:

DEBUG: JavaMail version 1.6.1
DEBUG: URL jar:file:/Users/baptistearnaud/.m2/repository/com/amazonaws/aws-java-sdk-ses/1.11.373/aws-java-sdk-ses-1.11.373.jar!/META-INF/javamail.providers
DEBUG: successfully loaded resource: jar:file:/Users/baptistearnaud/.m2/repository/com/amazonaws/aws-java-sdk-ses/1.11.373/aws-java-sdk-ses-1.11.373.jar!/META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], com.amazonaws.services.simpleemail.AWSJavaMailTransport=javax.mail.Provider[TRANSPORT,aws,com.amazonaws.services.simpleemail.AWSJavaMailTransport,Amazon Web Services LLC]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], aws=javax.mail.Provider[TRANSPORT,aws,com.amazonaws.services.simpleemail.AWSJavaMailTransport,Amazon Web Services LLC]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.office365.com", port 587, isSSL false
220 LO2P265CA0439.outlook.office365.com Microsoft ESMTP MAIL Service ready at Wed, 21 Nov 2018 11:01:22 +0000
DEBUG SMTP: connected to host "smtp.office365.com", port: 587
EHLO mbp-de-baptiste.lan
250-LO2P265CA0439.outlook.office365.com Hello [89.227.204.114]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "157286400"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
STARTTLS
220 2.0.0 SMTP server ready
EHLO mbp-de-baptiste.lan
250-LO2P265CA0439.outlook.office365.com Hello [89.227.204.114]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-AUTH LOGIN XOAUTH2
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "157286400"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN XOAUTH2"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: protocolConnect login, host=smtp.office365.com, user=SVC_ToGazer@uccint.onmicrosoft.com, 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 succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<foo1@foo1.com>
250 2.1.0 Sender OK
RCPT TO:<foo2@foo2.com>
250 2.1.5 Recipient OK
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   foo2@foo2.com
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Date: Wed, 21 Nov 2018 11:00:41 +0000 (UTC)
From: foo1@foo1.com
To: foo2@foo2.com
Message-ID: <681000169.0.1542798041668@mbp-de-baptiste.lan>
Subject: FOO
MIME-Version: 1.0
Content-Type: multipart/mixed; 
    boundary="----=_Part_1_1921144901.1542798041673"

------=_Part_1_1921144901.1542798041673
Content-Type: text/calendar; charset="utf-8"; method=REQUEST
Content-Transfer-Encoding: base64

QkVHSU46VkNBTEVOREFSClZFUlNJT046Mi4wClBST0RJRDotLy9HUlRnYXogQ29ycG9yYXRpb24v
L05PTlNHTUwgVG9nYXonZXIvL0ZSCk1FVEhPRDpSRVFVRVNUCkJFR0lOOlZFVkVOVApVSUQ6YTQ5
ODVkZjUtNzI1YS00NTA0LTgzNWYtZDhkNTU2ZjliMDIzQHRvZ2F6ZXIuY29tCkRUU1RBTVA6MjAx
ODExMjlUMTgwMDAwWgpPUkdBTklaRVI7Q049dG9nYXplckBpbnQuZ3J0Z2F6LmV1Om1haWx0bzp0
b2dhemVyQGludC5ncnRnYXouZXUKQVRURU5ERUU7Q1VUWVBFPUlORElWSURVQUw7Uk9MRT1SRVEt
UEFSVElDSVBBTlQ7ClBBUlRTVEFUPU5FRURTLUFDVElPTjtSU1ZQPVRSVUU7Q049QmFwdGlzdGUg
QXJuYXVkOwpYLU5VTS1HVUVTVFM9MDptYWlsdG86YmFwdF9pczJAaG90bWFpbC5jb20KRFRTVEFS
VDoyMDE4MTEyOVQxODAwMDAKRFRFTkQ6MjAxODExMjlUMjIwMDAwClNVTU1BUlk6QWZ0ZXJ3b3Jr
IGdheidwYWNobwpMT0NBVElPTjpQYXJpcyA4ZSBhcnIKREVTQ1JJUFRJT046QWZ0ZXJ3b3JrIG/D
uSBsJ29uIHZhIGTDqWd1c3RlciBkdSBib24gZ2FzcGFjaG8uIEonZXNww6hyZSBxdWUgbGUgamV1
IGRlIG1vdCB2b3VzIHBsYcOudC4uLiBFeGNlbGxlbnQhCkVORDpWRVZFTlQKRU5EOlZDQUxFTkRB
Ugo=
------=_Part_1_1921144901.1542798041673--
.
554 5.2.0 STOREDRV.Submission.Exception:InvalidRecipientsException; Failed to process message due to a permanent exception with message A message can't be sent because it contains no recipients. InvalidRecipientsException: A message can't be sent because it contains no recipients. [Hostname=AM6PR01MB5011.eurprd01.prod.exchangelabs.com]
DEBUG SMTP: got response code 554, with response: 554 5.2.0 STOREDRV.Submission.Exception:InvalidRecipientsException; Failed to process message due to a permanent exception with message A message can't be sent because it contains no recipients. InvalidRecipientsException: A message can't be sent because it contains no recipients. [Hostname=AM6PR01MB5011.eurprd01.prod.exchangelabs.com]

RSET
250 2.0.0 Resetting
DEBUG SMTP: MessagingException while sending, THROW: 
com.sun.mail.smtp.SMTPSendFailedException: 554 5.2.0 STOREDRV.Submission.Exception:InvalidRecipientsException; Failed to process message due to a permanent exception with message A message can't be sent because it contains no recipients. InvalidRecipientsException: A message can't be sent because it contains no recipients. [Hostname=AM6PR01MB5011.eurprd01.prod.exchangelabs.com]

任何想法为什么会有这种行为吗?

2 个答案:

答案 0 :(得分:2)

正如@Bill Shannon在评论部分中提到的那样,问题出在日历格式上。

您需要确保自己的ic通过this kind of validator

例如,在我的实现中:

"""BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//GRTgaz Corporation//NONSGML Togaz'er//FR
METHOD:REQUEST
BEGIN:VEVENT
UID:$id
ORGANIZER;RSVP=FALSE;PARTSTAT=ACCEPTED;
ROLE=CHAIR:mailto:SVC_ToGazer@uccint.onmicrosoft.com
ATTENDEE;RSVP=FALSE;PARTSTAT=ACCEPTED;
ROLE=REQ-PARTICIPANT:mailto:${to.email}
DTSTAMP:${startDate[0]}T${startDate[1]}Z
DTSTART:${startDate[0]}T${startDate[1]}
DTEND:${endDate[0]}T${endDate[1]}
SUMMARY:${meetup.name}
LOCATION:${meetup.address}
DESCRIPTION:${meetup.description}
END:VEVENT
END:VCALENDAR
"""

ORGANIZERATTENDEE道具无效。属性ROLE必须在同一行。所以我将其修改为:

"""BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//GRTgaz Corporation//NONSGML Togaz'er//FR
METHOD:REQUEST
BEGIN:VEVENT
UID:$id
ORGANIZER;RSVP=FALSE;PARTSTAT=ACCEPTED;ROLE=CHAIR
 :mailto:SVC_ToGazer@uccint.onmicrosoft.com
ATTENDEE;RSVP=FALSE;PARTSTAT=ACCEPTED;ROLE=REQ-PARTICIPANT
 :mailto:${to.email}
DTSTAMP:${startDate[0]}T${startDate[1]}Z
DTSTART:${startDate[0]}T${startDate[1]}
DTEND:${endDate[0]}T${endDate[1]}
SUMMARY:${meetup.name}
LOCATION:${meetup.address}
DESCRIPTION:${meetup.description}
END:VEVENT
END:VCALENDAR
"""

现在,它可以正常工作了。

答案 1 :(得分:1)

如前所述,有几种类型的在线验证器可以检查格式是否有效。这两个验证器可检测不同类型的错误。

例如,验证者将注意到的一件事是,每当您使用文本时,都必须转义以下字符:  \ ; , \n

验证器将某些情况视为警告(没有CRLF换行符,同一行中的字符过多)。

验证器无法检测到一些错误。例如,当组织者的电子邮件与收件人的电子邮件相等时,出现此SMTP错误。发现它不是显而易见的,但是我终于找到了问题的根源。

ORGANIZER;CN=Example:mailto:sameEmailAsTheRecipient@example.com

我希望Outlook可以改善iCal验证的反馈/错误消息!