Kod w momencie wysyłki danych wiadomości. Gdzieś w zmiennej data musiałem coś źle wpisać, ale ciężko znaleźć coś aktualnego dotyczącego SMTP i wysyłki załącznika.
List zostaje poprawnie wysłany, ale jego zawartość (treść załącznika) jest wrzucana do treści wiadomości, tj. dostaje takie coś w treści.
--------------320547182044673
Content-Type: text/plain; charset=US-ASCII
This is body
--------------320547182044673
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename= "dane.rar"
cmFy
--------------320547182044673--
Funkcja SendToStream ze zmienną jako tablica unsigned char, wysyła dane do strumienia, ale nie prosi o odpowiedź.
KOD cpp: UKRYJ
// Body
if (!this->_SMTP_SendToStream("DATA" + "\r\n")->StartsWith("354"))
{
return false;
}
// Sending data
String^ data = String::Empty;
String^ bound = this->Generate_Boundary();
data += "To: " + recip + "\r\n";
data += "From: <" + sender + ">\r\n";
data += "Subject: <" + subject + ">\r\n";
data += "MIME-Version: 1.0 " + "\r\n";
data += "Content-Type: multipart/mixed; " + "\r\n";
data += " boundary= \"" + bound + "\"\r\n";
data += "\r\n";
data += bound + " \r\n";
data += "Content-Type: text/plain; charset=US-ASCII " + "\r\n";
data += "\r\n";
data += body;
data += "\r\n";
data += bound + "\r\n";
data += "Content-Type: application/octet-stream " + "\r\n";
data += "Content-Transfer-Encoding: base64 " + "\r\n";
data += "Content-Disposition: attachment; " + "\r\n";
data += " filename= \"" + fileName + "\"" + "\r\n";
data += "\r\n";
array<unsigned char>^ buffer = Encoding::ASCII->GetBytes(data);
Stream^ dataStream = gcnew MemoryStream(Encoding::ASCII->GetBytes(Convert::ToBase64String(this->UploadData)));
dataStream->Position = 0;
array<unsigned char>^ uploadBuffer = gcnew array<unsigned char>(this->uploadBufferSize);
if (instream == nullptr)
{
this->_SMTP_SendToStream(buffer);
while (1)
{
readedBytes = dataStream->Read(uploadBuffer, 0, uploadBuffer->Length);
this->_SMTP_SendToStream(uploadBuffer, readedBytes);
if (readedBytes == 0)
{
break;
}
}
data = String::Empty;
data += " \r\n";
data += bound + "--" + " \r\n";
data += "\r\n.\r\n";
if (!this->_SMTP_SendToStream(data)->StartsWith("250"))
{
return false;
}
}
if (!this->_SMTP_SendToStream("DATA" + "\r\n")->StartsWith("354"))
{
return false;
}
// Sending data
String^ data = String::Empty;
String^ bound = this->Generate_Boundary();
data += "To: " + recip + "\r\n";
data += "From: <" + sender + ">\r\n";
data += "Subject: <" + subject + ">\r\n";
data += "MIME-Version: 1.0 " + "\r\n";
data += "Content-Type: multipart/mixed; " + "\r\n";
data += " boundary= \"" + bound + "\"\r\n";
data += "\r\n";
data += bound + " \r\n";
data += "Content-Type: text/plain; charset=US-ASCII " + "\r\n";
data += "\r\n";
data += body;
data += "\r\n";
data += bound + "\r\n";
data += "Content-Type: application/octet-stream " + "\r\n";
data += "Content-Transfer-Encoding: base64 " + "\r\n";
data += "Content-Disposition: attachment; " + "\r\n";
data += " filename= \"" + fileName + "\"" + "\r\n";
data += "\r\n";
array<unsigned char>^ buffer = Encoding::ASCII->GetBytes(data);
Stream^ dataStream = gcnew MemoryStream(Encoding::ASCII->GetBytes(Convert::ToBase64String(this->UploadData)));
dataStream->Position = 0;
array<unsigned char>^ uploadBuffer = gcnew array<unsigned char>(this->uploadBufferSize);
if (instream == nullptr)
{
this->_SMTP_SendToStream(buffer);
while (1)
{
readedBytes = dataStream->Read(uploadBuffer, 0, uploadBuffer->Length);
this->_SMTP_SendToStream(uploadBuffer, readedBytes);
if (readedBytes == 0)
{
break;
}
}
data = String::Empty;
data += " \r\n";
data += bound + "--" + " \r\n";
data += "\r\n.\r\n";
if (!this->_SMTP_SendToStream(data)->StartsWith("250"))
{
return false;
}
}
Jeszcze jedno pytanie. Rozumiem, że te ~30% więcej KB w wiadomości to wina kodowania do base64 ? Bo załącznik pierwotnie miał 3 bajty.
--
I jeszcze coś, The Bat odebrał wiadomość jako pustą treść
--------------320547182044673
Content-Type: text/plain; charset=US-ASCII
This is body
--------------320547182044673
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename= "dane.rar"
To:
--------------320547182044673--
wrzucił do załącznika o dziwnej nazwie (Cz.att).