trichview.com Forum Index trichview.com
TRichView support forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Demo] Sending HTML email. Saving MIME-encoded files.
Goto page Previous  1, 2
 
Post new topic   Reply to topic    trichview.com Forum Index -> Examples, Demos
View previous topic :: View next topic  
Author Message
wray



Joined: 14 Feb 2008
Posts: 38
Location: Romania

PostPosted: Thu Feb 14, 2008 8:59 pm    Post subject: No background Reply with quote

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 Smile)

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[i]->Stream->Size);
HTMLImages->Items[i]->Stream->Position = 0;
HTMLImages->Items[i]->Stream->ReadBuffer(s.c_str(), s.Length());
s = IdEncoderMIME1->EncodeString(IdEncoderMIME1->ClassType(),s);
s2 += "Content-Type: "+HTMLImages->Items[i]->ContentType +";\n\tname=\"" + HTMLImages->Items[i]->Name +"\"\nContent-Transfer-Encoding: base64\nContent-ID: <" + HTMLImages->Items[i]->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
Back to top
View user's profile Send private message
Sergey Tkachenko
Site Admin


Joined: 27 Aug 2005
Posts: 6599

PostPosted: Sat Feb 16, 2008 12:22 pm    Post subject: Reply with quote

Please send me a project reproducing the problem. I'll try to see what's wrong.
Back to top
View user's profile Send private message Visit poster's website
wray



Joined: 14 Feb 2008
Posts: 38
Location: Romania

PostPosted: Sun Feb 17, 2008 5:14 pm    Post subject: Reply with quote

Ok, i will send a PM.

You can test with your posted code, but translate it from delphi to c++, for me the result was the same, no background in mail.

Please test with a YAHOO mail, this is what i used, not outlook or other pop3 software.

Regards
Back to top
View user's profile Send private message
Sergey Tkachenko
Site Admin


Joined: 27 Aug 2005
Posts: 6599

PostPosted: Sun Feb 17, 2008 6:35 pm    Post subject: Reply with quote

May be yahoo web interface does not support background images in e-mails?
Back to top
View user's profile Send private message Visit poster's website
wray



Joined: 14 Feb 2008
Posts: 38
Location: Romania

PostPosted: Sun Feb 17, 2008 8:49 pm    Post subject: Reply with quote

Well, yes is very possible...

I just started using RichView and i do not know the advanced stuff, and i do not know how the HTML is formated, but if it used CSS styles, then i am almost positive the web interfaces blocks the backgroud...

http://www.xavierfrenette.com/articles/css-support-in-webmail/#selectors-properties-hotmail-1

Here are some details about what is allowed and what is not allowed on wide used web mails like Gmail, Yahoo and Hotmail

One thing is sure, on Gmail, the background is attached as picture but not displayed as background... Maybe is the case for Yahoo too.

---------------

Tell me if there is any other possibility to display text over a picture ?

If not, i will use headers and footers and hell with background Smile

Regards
Vlad
Back to top
View user's profile Send private message
Sergey Tkachenko
Site Admin


Joined: 27 Aug 2005
Posts: 6599

PostPosted: Mon Feb 18, 2008 6:53 am    Post subject: Reply with quote

You can use SaveHTMLToStream instead of SaveHTMLToStreamEx to save HTML without CSS.
And you can insert text in table with background picture (background picture can be assigned to the table itself or to table cell)
Back to top
View user's profile Send private message Visit poster's website
wray



Joined: 14 Feb 2008
Posts: 38
Location: Romania

PostPosted: Tue Feb 19, 2008 7:21 pm    Post subject: Reply with quote

I tried that too, it just seems webmails like yahoo HATE backgrounds...

Tried cell background and table background - same result Sad

BUT after final try i listened to you and saved HTML without CSS and IT WORKS !!!

THANKS - verified solution - cell background and saved without CSS

Payment is ok now, i just wait for key now, see you soon on members forum Wink

Regards
Vlad
Back to top
View user's profile Send private message
dmitry_oz



Joined: 30 Apr 2008
Posts: 6

PostPosted: Thu May 29, 2008 5:58 am    Post subject: load email in MIME format into TichViewEdit Reply with quote

Hi Sergey,

do you have DEMO for this?
Back to top
View user's profile Send private message
Sergey Tkachenko
Site Admin


Joined: 27 Aug 2005
Posts: 6599

PostPosted: Thu May 29, 2008 10:11 am    Post subject: Reply with quote

Demo for that?
http://www.trichview.com/support/files/mime.zip contains demos:
- saving EML/MHT file (HTML + images), for Delphi and for C++
- sending HTML email using Indy components (plain text + HTML + images + attached files), for Delphi
Back to top
View user's profile Send private message Visit poster's website
dmitry_oz



Joined: 30 Apr 2008
Posts: 6

PostPosted: Fri May 30, 2008 1:50 am    Post subject: Reply with quote

Sorry, I was not clear enough.

I was asking for DEMO on loading email into RichView.
My understanding is if email has bundled rtf/txt/html it should be possible to do so

Cheers,
Dmitry
Back to top
View user's profile Send private message
Sergey Tkachenko
Site Admin


Joined: 27 Aug 2005
Posts: 6599

PostPosted: Fri May 30, 2008 5:58 am    Post subject: Reply with quote

Sorry, no.
You should use any component that can disassemble mime file into separate parts-files, then use RvHtmlImporter to load HTML.

Note that HTML email has a nested structure like this:
<(text {HTML, image1, image2, ...}) file1, file2...>
If there are no files, the level () does not present.
If there are no images, the level {} does not present.
Back to top
View user's profile Send private message Visit poster's website
nikivanov



Joined: 18 Feb 2010
Posts: 2
Location: Russia

PostPosted: Tue Mar 23, 2010 2:18 pm    Post subject: Reply with quote

Sergey, could you create a similar example for Clever Internet Suite 7? I would not want to use the The Delphi Inspiration's DIMime unit. Perhaps it can be replaced by Mail Message or Encoder component from CIS 7?
Back to top
View user's profile Send private message Visit poster's website
Sergey Tkachenko
Site Admin


Joined: 27 Aug 2005
Posts: 6599

PostPosted: Fri Mar 26, 2010 4:04 pm    Post subject: Reply with quote

nikivanov, a demo is coming soon
Back to top
View user's profile Send private message Visit poster's website
nikivanov



Joined: 18 Feb 2010
Posts: 2
Location: Russia

PostPosted: Fri Mar 26, 2010 6:07 pm    Post subject: Reply with quote

Sergey, thank you very much, I'll wait ...
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    trichview.com Forum Index -> Examples, Demos All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group