No background
Posted: Thu Feb 14, 2008 8:59 pm
Hi,
first of all, from what i am seeing here, this might be the best support i saw ever. I am still using the demo version of RichView (there were 2 PayPals rejection, i still wonder why since they were PayPal2000, anyway i will use credit card and this is with with paypal )
Now the issue is like this:
I have to send a HTML email AND i have to write some text over a picture. To do this i figured out i have to set up a background and just andter the text where should be.
The problem is, in Email no background is shown. Everything else is ok, but no background, if i add a picture with AddPictureEx, everything is ok. If i add with BackgroundBitmap, no background is shown in email. The bmp is sent, since the mail had 500k length.
I tried to load a file in Microsoft Word and to play with Wrapping in Format Picture, and i made the picture floating with the text over it. But when i load it in RichView is not floating, is on his own paragraph.
Please advise...
Code is following: (BTW Indy Mime encode works perfectly)
Platform: Borland C++ Builder 5.0, Indy 10
TForm1 *Form1;
TJPEGImage *jp;
TJPEGImage *jp2;
Graphics::TBitmap *bmp;
Graphics::TBitmap *bmp2;
AnsiString GetImageContentType(TGraphic* gr)
{
if (gr->InheritsFrom(__classid(TJPEGImage)))
return "image/jpeg";
else if (gr->InheritsFrom(__classid(Graphics::TBitmap)))
return "image/bmp";
else if (gr->InheritsFrom(__classid(TIcon)))
return "image/x-icon";
else if (gr->InheritsFrom(__classid(TMetafile)))
return "application/octet-stream";
/*
else if (gr->InheritsFrom(__classid(TPNGObject)))
return "image/png";
else if (gr->InheritsFrom(__classid(TGifImage)))
return "image/gif";
*/
else
throw Exception("Unknown graphic format");
}
//---------------------------------------------------------------------------
// THTMLImageItem
//---------------------------------------------------------------------------
__fastcall THTMLImageItem::THTMLImageItem(TCollection* Collection)
: TCollectionItem(Collection)
{
Stream = new TMemoryStream;
}
//---------------------------------------------------------------------------
__fastcall THTMLImageItem::~THTMLImageItem()
{
delete Stream;
}
//---------------------------------------------------------------------------
// THTMLImagesCollection
//---------------------------------------------------------------------------
__fastcall THTMLImagesCollection::THTMLImagesCollection()
: TCollection(__classid(THTMLImageItem))
{
}
//---------------------------------------------------------------------------
THTMLImageItem* __fastcall THTMLImagesCollection::GetItem(int Index)
{
return (THTMLImageItem*)(TCollection::GetItem(Index));
}
//---------------------------------------------------------------------------
void __fastcall THTMLImagesCollection::SetItem(int Index, const THTMLImageItem* Value)
{
TCollection::SetItem(Index, (TCollectionItem*)Value);
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RichViewEdit1SaveImage2(TCustomRichView *Sender,
TGraphic *Graphic, TRVSaveFormat SaveFormat, const AnsiString Path,
const AnsiString ImagePrefix, int &ImageSaveNo, AnsiString &Location,
bool &DoDefault)
{
if (SaveFormat!=rvsfHTML)
return;
bmp2 = new Graphics::TBitmap;
try
{
bmp2->Assign(Graphic);
}
catch(Exception &E)
{
bmp2->Width = Graphic->Width;
bmp2->Height = Graphic->Height;
bmp2->Canvas->Draw(0,0,Graphic);
}
jp2 = new TJPEGImage();
jp2->Assign(bmp2);
delete bmp2;
AnsiString Ext = GraphicExtension((TGraphicClass)(Graphic->ClassType()));
Location = Format("image%d.%s", ARRAYOFCONST((ImageSaveNo, Ext)));
ImageSaveNo++;
THTMLImageItem* Item = (THTMLImageItem*)(HTMLImages->Add());
Graphic->SaveToStream(Item->Stream);
Item->Name = Location;
Item->ContentType = GetImageContentType(Graphic);
Location = "cid:"+Location;
DoDefault = false;
if(jp2 != Graphic) delete jp2;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
jp = new TJPEGImage();
bmp = new Graphics::TBitmap;
HTMLImages = new THTMLImagesCollection;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Gen_actClick(TObject *Sender)
{
AnsiString Target = "www.xxxxxxxxx.com";
bmp->Assign(Image2->Picture->Graphic);
RichViewEdit1->BackgroundBitmap = bmp;
RichViewEdit1->BackgroundStyle = bsCentered;
RichViewEdit1->AddBreakEx(4, rvbsLine, clBlue);
RichViewEdit1->AddNL("Activation code", 1, 1);
RichViewEdit1->AddNL("", 1, 1);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",4,0);
RichViewEdit1->AddNL(" ", 0, 0);
// RichViewEdit1->AddBulletEx("", 0, ImageList1, -1);
RichViewEdit1->Add(" Your activation code is: ", 2);
RichViewEdit1->AddNL(" ", 0, 0);
RichViewEdit1->Add("12345678",0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddBreakEx(4, rvbsLine, clBlue);
// RichViewEdit1->AddBulletEx("", 1, ImageList1, -1);
RichViewEdit1->AddNLTag(Target,3,1, (int)StrNew(Target.c_str()));
RichViewEdit1->Format();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SendClick(TObject *Sender)
{
AnsiString Result;
AnsiString s,s2;
WideString ws;
HTMLImages->Clear();
//saving text
TMemoryStream* Stream2 = new TMemoryStream();
RichViewEdit1->SaveTextToStreamW("", Stream2, 80, false, false);
Stream2->Seek(0,0);
ws.SetLength(Stream2->Size /2);
if(Stream2->Size != 0)
Stream2->ReadBuffer(ws,Stream2->Size);
s2 = IdEncoderMIME1->EncodeString(IdEncoderMIME1->ClassType(),Utf8Encode(ws));
delete Stream2;
//saving HTML
TStringStream* Stream = new TStringStream("");
RichViewEdit1->SaveHTMLToStreamEx(Stream, "", "Web Archive Demo", "", "", "", "",TRVSaveOptions() << rvsoUseCheckpointsNames << rvsoUTF8);
s = IdEncoderMIME1->EncodeString(IdEncoderMIME1->ClassType(),Stream->DataString); //MimeEncodeString(Stream->DataString);
delete Stream;
// now s contains HTML file without images, base64-encoded. saving it in MIME
AnsiString BOUNDARY_TEXT_AND_HTML = "----=_TEXT_AND_HTML_BOUNDARY_";
AnsiString BOUNDARY_MESSAGE_AND_PICTURES = "----=_MESSAGE_AND_PICS_BOUNDARY_";
AnsiString BOUNDARY_MAIN_AND_ATTACHMENTS = "----=_MAIN_AND_ATTACHMENTS_BOUNDARY_";
Result = "This is a multi-part message in MIME format.\n\n";
if(HTMLImages->Count > 0)
{
Result += "--" + BOUNDARY_MESSAGE_AND_PICTURES+"\n";
Result += "Content-Type: multipart/alternative;\n\tboundary=\"" + BOUNDARY_TEXT_AND_HTML +"\"\n\n--" +BOUNDARY_TEXT_AND_HTML + "\n";
}
else
Result += "--" + BOUNDARY_TEXT_AND_HTML + "\n";
Result += "Content-Type: text/plain;\n\tcharset=\"utf-8\"\nContent-Transfer-Encoding: base64\n\n";
Result += s2;
Result += "\n\n--" + BOUNDARY_TEXT_AND_HTML + "\n";
Result += "Content-Type: text/html;\n\tcharset=\"utf-8\"\nContent-Transfer-Encoding: base64\n\n";
Result += s;
Result += "\n\n--" + BOUNDARY_TEXT_AND_HTML +"--\n";
// saving images
for (int i=0; i<HTMLImages->Count; i++)
{
s2 = "\n--" + BOUNDARY_MESSAGE_AND_PICTURES + "\n";
s.SetLength(HTMLImages->Items->Stream->Size);
HTMLImages->Items->Stream->Position = 0;
HTMLImages->Items->Stream->ReadBuffer(s.c_str(), s.Length());
s = IdEncoderMIME1->EncodeString(IdEncoderMIME1->ClassType(),s);
s2 += "Content-Type: "+HTMLImages->Items->ContentType +";\n\tname=\"" + HTMLImages->Items->Name +"\"\nContent-Transfer-Encoding: base64\nContent-ID: <" + HTMLImages->Items->Name +">\n\n" + s + "\n";
Result += s2;
}
Result += "\n--" + BOUNDARY_MESSAGE_AND_PICTURES + "--\n";
IdMessage1->Clear();
IdMessage1->Date = Now();
IdMessage1->Subject = "[xxxxxxxxxxx] Activation Code !";
IdMessage1->Recipients->Add();
IdMessage1->Recipients->Items[0]->Address = "xxxxx@yahoo.com";
IdMessage1->Sender->Address = "support@xxxxxx.com";
IdMessage1->From->Name = "xxxxxxx Server";
IdMessage1->From->Address = "activation@xxxxxxx.com";
IdMessage1->Body->Text = Result;
IdMessage1->ExtraHeaders->Add("MIME-Version: 1.0");
if(HTMLImages->Count > 0)
{
IdMessage1->ExtraHeaders->Add("Content-Type: multipart/related;");
IdMessage1->ExtraHeaders->Add("\ttype=\"multipart/alternative\";");
IdMessage1->ExtraHeaders->Add("\tboundary=\"" + BOUNDARY_MESSAGE_AND_PICTURES +"\"");
}
else
{
IdMessage1->ExtraHeaders->Add("Content-Type: multipart/alternative;");
IdMessage1->ExtraHeaders->Add("\tboundary=\"" + BOUNDARY_TEXT_AND_HTML + "\"");
}
Form1->IdSMTP1->Host = "xxxxxx.ro";
Form1->IdSMTP1->Port = 25;
Form1->IdSMTP1->Username = "xxxx@xxxxx.ro";
Form1->IdSMTP1->Password = "xxxxxxx";
Form1->IdSMTP1->ConnectTimeout = 2000;
Form1->IdSMTP1->Connect();
Form1->IdSMTP1->Authenticate();
Form1->IdSMTP1->Send(IdMessage1);
Form1->IdSMTP1->Disconnect(true);
HTMLImages->Clear();
}
//---------------------------------------------------------------------------
Thank you in advance
Vlad
first of all, from what i am seeing here, this might be the best support i saw ever. I am still using the demo version of RichView (there were 2 PayPals rejection, i still wonder why since they were PayPal2000, anyway i will use credit card and this is with with paypal )
Now the issue is like this:
I have to send a HTML email AND i have to write some text over a picture. To do this i figured out i have to set up a background and just andter the text where should be.
The problem is, in Email no background is shown. Everything else is ok, but no background, if i add a picture with AddPictureEx, everything is ok. If i add with BackgroundBitmap, no background is shown in email. The bmp is sent, since the mail had 500k length.
I tried to load a file in Microsoft Word and to play with Wrapping in Format Picture, and i made the picture floating with the text over it. But when i load it in RichView is not floating, is on his own paragraph.
Please advise...
Code is following: (BTW Indy Mime encode works perfectly)
Platform: Borland C++ Builder 5.0, Indy 10
TForm1 *Form1;
TJPEGImage *jp;
TJPEGImage *jp2;
Graphics::TBitmap *bmp;
Graphics::TBitmap *bmp2;
AnsiString GetImageContentType(TGraphic* gr)
{
if (gr->InheritsFrom(__classid(TJPEGImage)))
return "image/jpeg";
else if (gr->InheritsFrom(__classid(Graphics::TBitmap)))
return "image/bmp";
else if (gr->InheritsFrom(__classid(TIcon)))
return "image/x-icon";
else if (gr->InheritsFrom(__classid(TMetafile)))
return "application/octet-stream";
/*
else if (gr->InheritsFrom(__classid(TPNGObject)))
return "image/png";
else if (gr->InheritsFrom(__classid(TGifImage)))
return "image/gif";
*/
else
throw Exception("Unknown graphic format");
}
//---------------------------------------------------------------------------
// THTMLImageItem
//---------------------------------------------------------------------------
__fastcall THTMLImageItem::THTMLImageItem(TCollection* Collection)
: TCollectionItem(Collection)
{
Stream = new TMemoryStream;
}
//---------------------------------------------------------------------------
__fastcall THTMLImageItem::~THTMLImageItem()
{
delete Stream;
}
//---------------------------------------------------------------------------
// THTMLImagesCollection
//---------------------------------------------------------------------------
__fastcall THTMLImagesCollection::THTMLImagesCollection()
: TCollection(__classid(THTMLImageItem))
{
}
//---------------------------------------------------------------------------
THTMLImageItem* __fastcall THTMLImagesCollection::GetItem(int Index)
{
return (THTMLImageItem*)(TCollection::GetItem(Index));
}
//---------------------------------------------------------------------------
void __fastcall THTMLImagesCollection::SetItem(int Index, const THTMLImageItem* Value)
{
TCollection::SetItem(Index, (TCollectionItem*)Value);
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RichViewEdit1SaveImage2(TCustomRichView *Sender,
TGraphic *Graphic, TRVSaveFormat SaveFormat, const AnsiString Path,
const AnsiString ImagePrefix, int &ImageSaveNo, AnsiString &Location,
bool &DoDefault)
{
if (SaveFormat!=rvsfHTML)
return;
bmp2 = new Graphics::TBitmap;
try
{
bmp2->Assign(Graphic);
}
catch(Exception &E)
{
bmp2->Width = Graphic->Width;
bmp2->Height = Graphic->Height;
bmp2->Canvas->Draw(0,0,Graphic);
}
jp2 = new TJPEGImage();
jp2->Assign(bmp2);
delete bmp2;
AnsiString Ext = GraphicExtension((TGraphicClass)(Graphic->ClassType()));
Location = Format("image%d.%s", ARRAYOFCONST((ImageSaveNo, Ext)));
ImageSaveNo++;
THTMLImageItem* Item = (THTMLImageItem*)(HTMLImages->Add());
Graphic->SaveToStream(Item->Stream);
Item->Name = Location;
Item->ContentType = GetImageContentType(Graphic);
Location = "cid:"+Location;
DoDefault = false;
if(jp2 != Graphic) delete jp2;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
jp = new TJPEGImage();
bmp = new Graphics::TBitmap;
HTMLImages = new THTMLImagesCollection;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Gen_actClick(TObject *Sender)
{
AnsiString Target = "www.xxxxxxxxx.com";
bmp->Assign(Image2->Picture->Graphic);
RichViewEdit1->BackgroundBitmap = bmp;
RichViewEdit1->BackgroundStyle = bsCentered;
RichViewEdit1->AddBreakEx(4, rvbsLine, clBlue);
RichViewEdit1->AddNL("Activation code", 1, 1);
RichViewEdit1->AddNL("", 1, 1);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",4,0);
RichViewEdit1->AddNL(" ", 0, 0);
// RichViewEdit1->AddBulletEx("", 0, ImageList1, -1);
RichViewEdit1->Add(" Your activation code is: ", 2);
RichViewEdit1->AddNL(" ", 0, 0);
RichViewEdit1->Add("12345678",0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddNL("",0,0);
RichViewEdit1->AddBreakEx(4, rvbsLine, clBlue);
// RichViewEdit1->AddBulletEx("", 1, ImageList1, -1);
RichViewEdit1->AddNLTag(Target,3,1, (int)StrNew(Target.c_str()));
RichViewEdit1->Format();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SendClick(TObject *Sender)
{
AnsiString Result;
AnsiString s,s2;
WideString ws;
HTMLImages->Clear();
//saving text
TMemoryStream* Stream2 = new TMemoryStream();
RichViewEdit1->SaveTextToStreamW("", Stream2, 80, false, false);
Stream2->Seek(0,0);
ws.SetLength(Stream2->Size /2);
if(Stream2->Size != 0)
Stream2->ReadBuffer(ws,Stream2->Size);
s2 = IdEncoderMIME1->EncodeString(IdEncoderMIME1->ClassType(),Utf8Encode(ws));
delete Stream2;
//saving HTML
TStringStream* Stream = new TStringStream("");
RichViewEdit1->SaveHTMLToStreamEx(Stream, "", "Web Archive Demo", "", "", "", "",TRVSaveOptions() << rvsoUseCheckpointsNames << rvsoUTF8);
s = IdEncoderMIME1->EncodeString(IdEncoderMIME1->ClassType(),Stream->DataString); //MimeEncodeString(Stream->DataString);
delete Stream;
// now s contains HTML file without images, base64-encoded. saving it in MIME
AnsiString BOUNDARY_TEXT_AND_HTML = "----=_TEXT_AND_HTML_BOUNDARY_";
AnsiString BOUNDARY_MESSAGE_AND_PICTURES = "----=_MESSAGE_AND_PICS_BOUNDARY_";
AnsiString BOUNDARY_MAIN_AND_ATTACHMENTS = "----=_MAIN_AND_ATTACHMENTS_BOUNDARY_";
Result = "This is a multi-part message in MIME format.\n\n";
if(HTMLImages->Count > 0)
{
Result += "--" + BOUNDARY_MESSAGE_AND_PICTURES+"\n";
Result += "Content-Type: multipart/alternative;\n\tboundary=\"" + BOUNDARY_TEXT_AND_HTML +"\"\n\n--" +BOUNDARY_TEXT_AND_HTML + "\n";
}
else
Result += "--" + BOUNDARY_TEXT_AND_HTML + "\n";
Result += "Content-Type: text/plain;\n\tcharset=\"utf-8\"\nContent-Transfer-Encoding: base64\n\n";
Result += s2;
Result += "\n\n--" + BOUNDARY_TEXT_AND_HTML + "\n";
Result += "Content-Type: text/html;\n\tcharset=\"utf-8\"\nContent-Transfer-Encoding: base64\n\n";
Result += s;
Result += "\n\n--" + BOUNDARY_TEXT_AND_HTML +"--\n";
// saving images
for (int i=0; i<HTMLImages->Count; i++)
{
s2 = "\n--" + BOUNDARY_MESSAGE_AND_PICTURES + "\n";
s.SetLength(HTMLImages->Items->Stream->Size);
HTMLImages->Items->Stream->Position = 0;
HTMLImages->Items->Stream->ReadBuffer(s.c_str(), s.Length());
s = IdEncoderMIME1->EncodeString(IdEncoderMIME1->ClassType(),s);
s2 += "Content-Type: "+HTMLImages->Items->ContentType +";\n\tname=\"" + HTMLImages->Items->Name +"\"\nContent-Transfer-Encoding: base64\nContent-ID: <" + HTMLImages->Items->Name +">\n\n" + s + "\n";
Result += s2;
}
Result += "\n--" + BOUNDARY_MESSAGE_AND_PICTURES + "--\n";
IdMessage1->Clear();
IdMessage1->Date = Now();
IdMessage1->Subject = "[xxxxxxxxxxx] Activation Code !";
IdMessage1->Recipients->Add();
IdMessage1->Recipients->Items[0]->Address = "xxxxx@yahoo.com";
IdMessage1->Sender->Address = "support@xxxxxx.com";
IdMessage1->From->Name = "xxxxxxx Server";
IdMessage1->From->Address = "activation@xxxxxxx.com";
IdMessage1->Body->Text = Result;
IdMessage1->ExtraHeaders->Add("MIME-Version: 1.0");
if(HTMLImages->Count > 0)
{
IdMessage1->ExtraHeaders->Add("Content-Type: multipart/related;");
IdMessage1->ExtraHeaders->Add("\ttype=\"multipart/alternative\";");
IdMessage1->ExtraHeaders->Add("\tboundary=\"" + BOUNDARY_MESSAGE_AND_PICTURES +"\"");
}
else
{
IdMessage1->ExtraHeaders->Add("Content-Type: multipart/alternative;");
IdMessage1->ExtraHeaders->Add("\tboundary=\"" + BOUNDARY_TEXT_AND_HTML + "\"");
}
Form1->IdSMTP1->Host = "xxxxxx.ro";
Form1->IdSMTP1->Port = 25;
Form1->IdSMTP1->Username = "xxxx@xxxxx.ro";
Form1->IdSMTP1->Password = "xxxxxxx";
Form1->IdSMTP1->ConnectTimeout = 2000;
Form1->IdSMTP1->Connect();
Form1->IdSMTP1->Authenticate();
Form1->IdSMTP1->Send(IdMessage1);
Form1->IdSMTP1->Disconnect(true);
HTMLImages->Clear();
}
//---------------------------------------------------------------------------
Thank you in advance
Vlad