Kitura / Swift-SMTP

Swift SMTP client
Apache License 2.0
260 stars 60 forks source link

Swift-SMTP interoperability problem with Yahoo SMTP for 8k+ attachments #98

Open darrellroot opened 5 years ago

darrellroot commented 5 years ago

I'm not sure whether this problem with worthy of your attention, since (so far) it seems to be specific to one email provider and for large attachments only. But I thought I'd report it in case more providers are affected.

When sending an attachment of size 8k+ from my Yahoo account and using smtp.mail.yahoo.com as my SMTP server, I get the following error message:

Bad response received for command. command: ( .), response: 500 Line length exceeded. See RFC 2821 #4.5.3.1.

Sending an attachment of size 4k via Yahoo succeeds.

Sending an attachment of size 8k via Mac/iCloud SMTP infrastructure succeeds.

This is in a MacOS app with the following version information:

Swift 4.2 Xcode 10.1 MacOS 10.14.2 SwiftSMTP 5.1.0 LoggerAPI 1.8.0 Cryptor 1.0.23 SSLService 1.0.44 Socket 1.0.44

Below is my "send email" code showing full parameters from my test MacOS project. I have a test project if that is helpful.

Darrell

@IBAction func sendEmailButton(_ sender: NSButton) {
    scrollTextOutlet.string = ""
    let serverHostname = serverHostnameOutlet.stringValue
    let fromAddress = fromAddressOutlet.stringValue
    let fromPassword = fromPasswordOutlet.stringValue
    let toAddress = toAddressOutlet.stringValue
    let smtp = SMTP(hostname: serverHostname, email: fromAddress, password: fromPassword, port: 587, tlsMode: .requireSTARTTLS, tlsConfiguration: nil, authMethods: [], domainName: "localhost")
    let sender = Mail.User(name: "smtp test email user", email: fromAddress)
    let recipient = Mail.User(name: "test recipient", email: toAddress)
    var mail: Mail
    if attachmentCheckbox?.state.rawValue == 1 {
        self.scrollTextOutlet.string += "using attachment \(self.selectedPath)\n"
        let attachment = Attachment(filePath: self.selectedPath)
        mail = Mail(from: sender, to: [recipient], cc: [], bcc: [], subject: "test email subject", text: "test email body", attachments: [attachment], additionalHeaders: [:])

    } else {
        self.scrollTextOutlet.string += "sending email without attachment\n"
        mail = Mail(from: sender, to: [recipient], cc: [], bcc: [], subject: "test email subject", text: "test email body", attachments: [], additionalHeaders: [:])
    }
    smtp.send(mail) { (error) in
        if let error = error {
            self.scrollTextOutlet.string += "email error \(error)\n"
            if let error = error as? SMTPError {
                self.scrollTextOutlet.string += "\(error.description)\n"
            } else {
                self.scrollTextOutlet.string += "\(error.localizedDescription)\n"
            }
        } else {
            self.scrollTextOutlet.string += "test mail sent successfully\n"
        }
    }
}