mirror of
https://github.com/stefanocasazza/ULib.git
synced 2025-09-28 19:05:55 +08:00
Hackish extension to smtpClient to support hosts that require authentication (microsoft/gmail)
should be full backward compatible.
This commit is contained in:
parent
94c8f61fec
commit
9d5fcf1b20
|
@ -69,6 +69,8 @@ public:
|
|||
GREET = 220, // greeting from server
|
||||
GOODBYE = 221, // server acknolages quit
|
||||
SUCCESSFUL = 250, // command successful
|
||||
AUTHENTICATED = 235, // Authentication successful
|
||||
CHALLENGE = 334, // Login Credential Reqested
|
||||
READYDATA = 354, // server ready to receive data
|
||||
UNAVAILABLE = 450, // service not available
|
||||
ERR_PROCESSING = 451, // error in processing
|
||||
|
@ -116,7 +118,8 @@ public:
|
|||
UString getRecipientAddress() const { return rcptoAddress; }
|
||||
|
||||
bool startTLS();
|
||||
bool sendMessage(bool secure = false);
|
||||
bool authLogin(const UString* username, const UString* password);
|
||||
bool sendMessage(bool secure = false, const UString* username = U_NULLPTR, const UString* password = U_NULLPTR);
|
||||
|
||||
void setDomainName( const UString& name) { domainName = name; }
|
||||
void setMessageBody( const UString& message) { messageBody = message; }
|
||||
|
|
|
@ -172,8 +172,10 @@ U_NO_EXPORT void USmtpClient::setStateFromResponse()
|
|||
{
|
||||
case -1: state = CERROR; break;
|
||||
case GREET: state = LOG_IN; break;
|
||||
case CHALLENGE: state = LOG_IN; break;
|
||||
case GOODBYE: state = QUIT; break;
|
||||
case READYDATA: state = DATA; break;
|
||||
case AUTHENTICATED: response = SUCCESSFUL; break;
|
||||
|
||||
case SUCCESSFUL:
|
||||
{
|
||||
|
@ -237,9 +239,31 @@ bool USmtpClient::startTLS()
|
|||
U_RETURN(false);
|
||||
}
|
||||
|
||||
bool USmtpClient::authLogin(const UString* username, const UString* password)
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "USmtpClient::auth_login()")
|
||||
syncCommand(U_CONSTANT_TO_PARAM("HELO"));
|
||||
|
||||
#ifdef USE_LIBSSL
|
||||
if (((USSLSocket*)this)->isSSLActive()
|
||||
&& username->isBase64() && password->isBase64()){
|
||||
|
||||
if (syncCommand(U_CONSTANT_TO_PARAM("auth login"))
|
||||
&& syncCommand(username->c_str(),username->size())
|
||||
&& syncCommand(password->c_str(),password->size())
|
||||
&& response == SUCCESSFUL){
|
||||
U_RETURN(true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
||||
|
||||
// Execute an smtp transaction
|
||||
|
||||
bool USmtpClient::sendMessage(bool secure)
|
||||
bool USmtpClient::sendMessage(bool secure, const UString* username, const UString* password)
|
||||
{
|
||||
U_TRACE(0, "USmtpClient::sendMessage(%b)", secure)
|
||||
|
||||
|
@ -267,9 +291,18 @@ bool USmtpClient::sendMessage(bool secure)
|
|||
{
|
||||
U_RETURN(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(username && password)
|
||||
{
|
||||
if(!authLogin(username,password)){
|
||||
U_RETURN(false);
|
||||
}
|
||||
}
|
||||
|
||||
(void) syncCommand(U_CONSTANT_TO_PARAM("ehlo %v"), domainName.rep);
|
||||
}
|
||||
}
|
||||
|
||||
if (response != SUCCESSFUL) U_RETURN(false);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user