Download

FSocket-Send Mail [SMTP Problem]

Hi.
I am using FSocket to make a send mail function.
The protocol used is SMTP.
So far everything is fine, but when I send “STARTTLS”, and then send any orders are not reply.
I did a variety of checks I knew but did not find out where the problem was.
Can anyone help me?
Here is my code:


bool ULuoyuLibraryBPLibrary::Recv(FSocket* Socket)
{
	bool bIsComplete = false;
	if (Socket->GetConnectionState() == ESocketConnectionState::SCS_Connected)
	{
		uint32 PendingSize;
		int32  RecvReader;
		while (!Socket->HasPendingData(PendingSize))
		{
			UE_LOG(LogTemp, Warning, TEXT("Wait data to read"));
		};
		uint8* RecvBuff = new uint8[PendingSize + 1];
		bIsComplete = Socket->Recv(RecvBuff, PendingSize, RecvReader);
		RecvBuff[PendingSize] = '\0';
		FString DebugMessage(reinterpret_cast<const char*>(RecvBuff));
		GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, DebugMessage);
		delete]RecvBuff;
	}
	else
	{
		FString DebugMessage("Connection lost");
		GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, DebugMessage);
	}
	return bIsComplete;
}

int32 ULuoyuLibraryBPLibrary::Logon(FSocket* Socket, const FMailInfo& MailInfo)
{
	FString SendStr("HELO ");
	SendStr.Append(MailInfo.SenderName);
	SendStr.Append("
");
	TArray<uint8> SendBuff = ConvertToUTF8(SendStr);
	int32 SendReader;
	if (Socket->Send(SendBuff.GetData(), SendBuff.Num(), SendReader) == false || Recv(Socket) == false)
	{
		return 1;
	}

	SendStr.Empty();
	SendStr.Append("EHLO ");
	SendStr.Append(MailInfo.ServerName.ToString());
	SendStr.Append("
");
	SendBuff = ConvertToUTF8(SendStr);
	if (Socket->Send(SendBuff.GetData(), SendBuff.Num(), SendReader) == false || Recv(Socket) == false)
	{
		return 2;
	}

	SendStr.Empty();
	SendStr.Append("STARTTLS 
");
	SendBuff = ConvertToUTF8(SendStr);
	if (Socket->Send(SendBuff.GetData(), SendBuff.Num(), SendReader) == false || Recv(Socket) == false)
	{
		return 3;
	}

	SendStr.Empty();
	SendStr.Append("AUTH LOGIN
");
	SendBuff = ConvertToUTF8(SendStr);
	if (Socket->Send(SendBuff.GetData(), SendBuff.Num(), SendReader) == false || Recv(Socket) == false)
	{
		return 4;
	}
	return 0;
}


TArray<uint8> ULuoyuLibraryBPLibrary::ConvertToUTF8(const FString& InString)
{
	FString UseStr(InString);
	TCHAR* SendData = UseStr.GetCharArray().GetData();
	int32 DataLen = FCString::Strlen(SendData);
	uint8* Temp = (uint8*)TCHAR_TO_UTF8(SendData);
	TArray<uint8> SendTemp;
	for (int i = 0; i < DataLen; i++)
	{
		SendTemp.Add(Temp*);
	}

	return SendTemp;
}