I use this steps for send emails on android:
//Download
libcrypto.so and libssl.so
//Components
IdSSLIOHandlerSocketOpenSSL
Destination=smtp.yandex.ru:465
Host=smtp.yandex.ru
Port=465
IdSMTP
Password=***
Username=***
Host=smtp.yandex.ru
Port=465
IdMessage
CharSet=windows-1251
ContentType=text/plain
Encoding=meDefault
Subject=Hello
Code: Select all
#include <IdSSLOpenSSLHeaders.hpp>
#include "IdAttachmentFile.hpp"
#include <IdMessageBuilder.hpp>
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
IdOpenSSLSetLibPath(System::Ioutils::TPath::GetDocumentsPath());
}
//*********************************************
//*********************************************
void __fastcall TFormServis::IdMessage1InitializeISO(System::WideChar &VHeaderEncoding,
UnicodeString &VCharSet)
{
VCharSet = L"UTF-8";
VHeaderEncoding = L'B';
}
void __fastcall TFormServis::Button3Click(TObject *Sender)
{
try
{
IdMessage1->Clear();
IdMessage1->Subject = L"Hello";
IdMessage1->From->Address = L"lenailicheva@yandex.ru";
IdMessage1->From->Domain = L"yandex.ru";
IdMessage1->From->Text = L"lenailicheva@yandex.ru";
IdMessage1->From->User = L"lenailicheva";
TIdEMailAddressItem *Item = IdMessage1->Recipients->Add();
Item->User = Trim(Edit3->Text);
Item->Domain = L"yandex.ru";
//if need attachment
std::unique_ptr<TIdMessageBuilderPlain> builder(new TIdMessageBuilderPlain);
builder->PlainText->Text = L"From: " + Edit2->Text;
builder->PlainTextCharSet = L"utf-8";
builder->PlainTextContentTransfer = L"binary";
String att = System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath(), L"pic.jpg");
builder->Attachments->Add(att);
builder->FillMessage(IdMessage1);
IdSMTP1->Connect();
try {
IdSMTP1->Send(IdMessage1);
}
__finally {
IdSMTP1->Disconnect();
}
ShowMessage(L"Email successfully sent.");
}
catch (const EIdOSSLCouldNotLoadSSLLibrary &)
{
String ErMessage = WhichFailedToLoad();
String path = System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetSharedDownloadsPath(), L"error.ini");
if(FileExists(path))
{
std::unique_ptr<TIniFile> FileINI(new TIniFile(path));
FileINI->WriteString(L"ERROR",L"error",ErMessage);
ShowMessage(L"Write in error.ini");
}
else
{
ShowMessage(L"No file error.ini");
}
}
catch (const Exception &E)
{
String MES = E.Message;
ShowMessage(MES);
}
}
Thanks.