Sending email issue.
-
I try to send
uint32_t COMMANDS::Mail(uint32_t argc, char** args) { QStringList files; Smtp* smtp = new Smtp("mail_from@gmail.com", "pass", "smtp.gmail.com", 465); smtp->sendMail("mail_from@gmail.com", "mail_to@gmail.com" , "Test", "Hello", files); return MSG_OK; }
But I get
Server response code: "535"
Server response: "535-5.7.8 Username and Password not accepted.What user name and password it expects?
-
@jsulm
The only relation - I use a Qt class (smtp). So may be I do something wrong.I log with "pass" to "mail_from@gmail.com" and can send an email from it. So "mail_from@gmail.com" and "pass" seems perfectly valid to me.
-
@jenya7 said in Sending email issue.:
I use a Qt class (smtp)
Smtp is not a Qt class.
From where did you get it? -
@jsulm said in Sending email issue.:
@jenya7 said in Sending email issue.:
I use a Qt class (smtp)
Smtp is not a Qt class.
From where did you get it?I meant - implemented in Qt.
Smtp::Smtp( const QString &user, const QString &pass, const QString &host, int port, int timeout ) { socket = new QSslSocket(this); connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead())); connect(socket, SIGNAL(connected()), this, SLOT(connected() ) ); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this,SLOT(errorReceived(QAbstractSocket::SocketError))); connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(stateChanged(QAbstractSocket::SocketState))); connect(socket, SIGNAL(disconnected()), this,SLOT(disconnected())); this->user = user; this->pass = pass; this->host = host; this->port = port; this->timeout = timeout; } void Smtp::sendMail(const QString &from, const QString &to, const QString &subject, const QString &body, QStringList files) { message = "To: " + to + "\n"; message.append("From: " + from + "\n"); message.append("Subject: " + subject + "\n"); //Let's intitiate multipart MIME with cutting boundary "frontier" message.append("MIME-Version: 1.0\n"); message.append("Content-Type: multipart/mixed; boundary=frontier\n\n"); message.append( "--frontier\n" ); //message.append( "Content-Type: text/html\n\n" ); //Uncomment this for HTML formating, coment the line below message.append( "Content-Type: text/plain\n\n" ); message.append(body); message.append("\n\n"); if(!files.isEmpty()) { qDebug() << "Files to be sent: " << files.size(); foreach(QString filePath, files) { QFile file(filePath); if(file.exists()) { if (!file.open(QIODevice::ReadOnly)) { qDebug("Couldn't open the file"); QMessageBox::warning(nullptr, tr( "Qt Simple SMTP client" ), tr( "Couldn't open the file\n\n" )); return ; } QByteArray bytes = file.readAll(); message.append( "--frontier\n" ); message.append( "Content-Type: application/octet-stream\nContent-Disposition: attachment; filename="+ QFileInfo(file.fileName()).fileName() +";\nContent-Transfer-Encoding: base64\n\n" ); message.append(bytes.toBase64()); message.append("\n"); } } } else qDebug() << "No attachments found"; message.append( "--frontier--\n" ); message.replace( QString::fromLatin1( "\n" ), QString::fromLatin1( "\r\n" ) ); message.replace( QString::fromLatin1( "\r\n.\r\n" ),QString::fromLatin1( "\r\n..\r\n" ) ); this->from = from; rcpt = to; state = Init; socket->connectToHostEncrypted(host, static_cast<quint16>(port)); //"smtp.gmail.com" and 465 for gmail TLS if (!socket->waitForConnected(timeout)) { qDebug() << socket->errorString(); } t = new QTextStream( socket ); }
-
@jenya7 said in Sending email issue.:
Smtp::sendMail
It looks like you're not using user name and password when sending mails.
-
@jsulm said in Sending email issue.:
@jenya7 said in Sending email issue.:
Smtp::sendMail
It looks like you're not using user name and password when sending mails.
I see. It was advised as a reliable source.
Do we have any reliable example?
-
Hmm...I try this example.
The same problem. Here// Sending command: AUTH PLAIN base64('\0' + username + '\0' + password) sendMessage("AUTH PLAIN " + QByteArray().append((char) 0).append(user).append((char) 0).append(password).toBase64()); // Wait for the server's response waitForResponse(); // If the response is not 235 then the authentication was faild if (responseCode != 235) { emit smtpError(AuthenticationFailedError); return false; }
I get responseCode = 535.
-
@jenya7 said in Sending email issue.:
this example
IIRC gmail, blocks IMAP ad pop3 by default, you have to log in to your gmail account and enable it in the settings
- Go to "Settings", e.g. click on the "Gears" icon and select "Settings".
- Click on "Forwarding and POP/IMAP".
- Enable "IMAP Access" and/or "POP Download"
-
@jenya7 looks good.
have you seen this SO topic about response code 535?
You can try the solution posted there, see if that helps