1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| //---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ImgParser2000"
#pragma link "Mail2000"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
OpenDialog1->InitialDir = ExtractFilePath(Application->ExeName)+"Newsletter";
if (OpenDialog1->Execute() )
{Memo1->Lines->LoadFromFile(OpenDialog1->FileName); }
ImgParser20001->HTMLText->Text = Memo1->Lines->Text;
ImgParser20001->Parse();
ProgressBar1->Position = 0;
StaticText1->Caption = "";
//////////// here
char* Position;
char* OldPos;
char* P;
if( ImgParser20001->CreateCID()) //si CreateCID est une méthode ou if( ImgParser20001->CreateCID) si CreateCID est une propriété
{
Memo1->Lines->Text = ImgParser20001->HTMLText->Text;
ProgressBar1->Position = 0;
StaticText1->Caption = "";
}
P = Memo1->Lines->Text.c_str();
Position = StrPos(P, "cid:");
while(Position != NULL)
{
Memo1->SelStart = Position-P;
Memo1->SelLength = 4;
OldPos = Position+4;
Position = StrPos(OldPos, "cid:");
}
//////////// here
SMTP2->Host ="smtp.truc.fr";
SMTP2->UserName = "user";
SMTP2->Password = "pass";
if (SMTP2->Connect())
{
if (SMTP2->Helo())
{
Msg->Reset();
Msg->ToList->Clear();
Msg->CcList->Clear();
Msg->SetFrom("cedtest", "cedtest@test.fr");
// deux lignes du dessous avec SendMessageA()
// Msg->SetReplyTo("cedtest", "cedrc@numericable.fr");
// Msg->ToList->Add("cedtest", "cedrc@numericable.fr");
Msg->Subject = "IMGParser-Testnewsletter";
ImgParser20001->HTMLText->Text = Memo1->Text;
ImgParser20001->AttachFiles();
ImgParser20001->CreateCID();
Msg->SetTextHTML(ImgParser20001->HTMLText->Text);
//////// ImgParser20001->LBNewIMGTags->Items->Add();
Msg->SetTextPlain("This E-Mail needs a HTML Mail-Client1");
if (Msg->NeedRebuild)
{ Msg->RebuildBody();}
if ( //SMTP2->SendMessageA()
SMTP2->SendMessageTo("emailfrom","emailto")
)
{ ShowMessage("Newsletter sent."); }
else
{ ShowMessage("Error: Newsletter not sent."); }
}
SMTP2->Quit();
}
ProgressBar1->Position = 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ImgParser20001Progress(TObject *Sender,
TProgressMode Mode, int Max, int Position, AnsiString Info)
{
ProgressBar1->Max = Max;
ProgressBar1->Position = Position;
StaticText1->Caption = Info;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SMTP2Progress(TObject *Sender, int Total,
int Current)
{
ProgressBar1->Max = Total;
ProgressBar1->Position = Current;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
SMTP2->Port = 25 ;
SMTP2->TimeOut = 60 ;
SMTP2->MailMessage = Msg ;
SMTP2->PacketSize = 102400 ;
SMTP2->OnProgress = SMTP2Progress ;
SMTP2->Handshaking = hsAuto ;
Msg->Charset = "iso-8859-1" ;
Msg->TextEncoding = etQuotedPrintable ;
Msg->AttachEncoding = etQuotedPrintable ;
Msg->EmbedMethod = emContentID ;
Msg->ContentLocationBase = "http://localhost/" ;
ImgParser20001->CheckFilenames = True ;
ImgParser20001->MailMessage = Msg ;
}
//--------------------------------------------------------------------------- |
Partager