Kitura / Swift-SMTP

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

send email from gmail not working #90

Closed imgruntw closed 6 years ago

imgruntw commented 6 years ago

I can't send email from my gmail account with following code: ` import SwiftSMTP

public final class SwiftToolBoxCore { public func send() -> Void { let smtp = SMTP( hostname: "smtp.gmail.com", email: "myaccount@gmail.com", password: "mypassword", tlsMode: .requireSTARTTLS )

    let fromUser = Mail.User(
        name: "- -",
        email: "myaccount@gmail.com"
    )
    let toUser = Mail.User(
        email: "otheraccount@gmail.com"
    )

    let mail = Mail(
        from: fromUser,
        to: [toUser],
        subject: "subject",
        text: "content text"
    )

    smtp.send(mail) { (error) in
        if let error = error {
            print(error)
        }
    }
}

} `

There is no error message. Not secure apps are allowed on my gmail account. What I am doing wrong?

quanvo87 commented 6 years ago

Hmm. Maybe that name for the fromUser is causing problems? Would it be possible for you to share the repo you're using?

imgruntw commented 6 years ago

I am thanking for speedy responses! Here is my repo: https://github.com/imgruntw/SwiftToolBox

quanvo87 commented 6 years ago

How are you running this project? When I run, nothing is happening. It may not be related to Swift-SMTP.

imgruntw commented 6 years ago

the Method: send() in /SwiftToolBox/Sources/SwiftToolBoxCore/SwiftToolBoxCore is executed, but without sending an email and without any errors

quanvo87 commented 6 years ago

Perhaps execution of the program is ending before the asynchronous task can finish. When I put a print statement in the closure of smtp.send(), the print statement is not executed but the program returns with exit code 0.

imgruntw commented 6 years ago

Thanks, waiting for end of the asynchronous task with was the solution .