How can I store emails locally when I use indy to receive emails? It is best to store the emails in the database.

Source: Internet
Author: User
How to store emails locally when indy is used to receive emails, preferably in the database Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiNetwork/html/delphi_20061215094636123.html
Now you can use indy to receive emails, but you don't know how to save them, how to save foxmail, or how to save them to the database, I feel that his database type is quite troublesome. Isn't the attachments usually not stored in the database?
Please advise

You can write a column to show it to you ~~

****** ******************************
Function Trec_mail.Get_Receive (lett_index: OleVariant): OleVariant;
Var
Nmm_strUidl, nmm_strAttachFileName: string;
Nmm_strDirName, nmm_strUrlPath: string;
Nmm_strAttachFileUrl, nmm_strAttachFilePath: widestring;
Nmm_index: integer;
Nmm_strbody: widestring;
Nmm_strdecode: string;
Begin
Try
Nmg_intLetterIndex: = strtoint (lett_index); // global variable email id
Nmm_strUidl: = trim (get_uid );
Nmg_msgBody.clear;
Nmg_msgBody.NoDecode: = false;
Nmg_msgBody.IsEncoded: = true;
Try
Nmg_pop.Retrieve (nmg_intLetterindex, nmg_msgBody );
Except
Result: = '';
Exit;
End;
Nmg_msgHead.clear;
Nmg_msgHead.NoDecode: = false;
Nmg_msgHead.IsEncoded: = true;
Try
Nmg_pop.RetrieveHeader (nmg_intLetterIndex, nmg_msgHead );
Except
Result: = '';
Exit;
End;
If nmg_strMailUserDir = ''then
Begin
Nmm_strDirName: = nmg_strRootDir + nmm_strUidl;
Nmm_strUrlPath: = nmg_strRootUrlPath + nmm_strUidl;
End
Else
Begin
Nmm_strDirName: = nmg_strRootDir + nmg_strMailUserDir + '\' + nmm_strUidl;
Nmm_strUrlPath: = nmg_strRootUrlPath + nmg_strMailUserDir + '/' + nmm_strUidl;
End;
ForceDirectories (nmm_strDirName );
FormAttachHtm;
Nmg_blnHasAttOut: = false;
********** *****************************
Try
If nmg_msgBody.messageparts.Count = 0 then nmg_stsContent: = nmg_msgBody.Body
Else begin
For nmm_index: = 0 to pred (nmg_msgBody.messageparts.Count) do
If nmg_msgBody.MessageParts.Items [nmm_index] is TIdText then nmg_stsContent: = TIdText (nmg_msgBody.MessageParts.Items [nmm_index]). Body;
End;
Except
Result: = '';
Exit;
End;
If (pos ('html> ', nmg_stsContent.text) or (pos ('html>', nmg_stsContent.text) <1 then nmg_stsContent.text: = '<pre>' + nmg_stsContent.text + '</pre> ';
********** *****************************
For nmm_index: = 0 to pred (nmg_msgBody.messageparts.Count) do
Begin
If (nmg_msgBody.MessageParts.Items [nmm_index] is TIdAttachment) then
Begin
Nmm_strAttachFileName: = DecodeHeader (TIdAttachment (nmg_msgBody.MessageParts.Items [nmm_index]). Filename );
Nmm_strAttachFileUrl: = nmm_strUrlPath;
Nmm_strdecode: = (tidattachment (nmg_msgBody.MessageParts.Items [nmm_index]). ContentDisposition );
If trim (nmm_strdecode) <> ''then
Begin
Nmm_strAttachFilePath: = nmm_strDirName + '\ attachment \' + inttostr (nmm_index );
ForceDirectories (nmm_strAttachFilePath );
Nmm_strAttachFileUrl: = nmm_strAttachFileUrl + '/attachment/' + inttostr (nmm_index) + '/' + nmm_strAttachFileName;
Nmm_strAttachFilePath: = nmm_strAttachFilePath + '\' + nmm_strAttachFileName;
Try
If not fileexists (nmm_strAttachFilePath) then
Tidattachment (nmg_msgBody.MessageParts.Items [nmm_index]). SaveToFile (nmm_strAttachFilePath );
Except
Continue;
End;
Nmg_stsAttach.add ('<a href = "' + nmm_strAttachFileUrl + '" target = _ blank>' + nmm_strAttachFileName + '</a> <BR> ');
Nmg_blnHasAttOut: = true;
End
Else
Begin
Nmm_strAttachFilePath: = nmm_strDirName + '\ Image \' + inttostr (nmm_index );
Nmm_strAttachFileUrl: = nmm_strAttachFileUrl + '\ Image \' + inttostr (nmm_index) + '\' + nmm_strAttachFileName;
ForceDirectories (nmm_strAttachFilePath );
Nmm_strAttachFilePath: = nmm_strAttachFilePath + '\' + nmm_strAttachFileName;
Try
If not fileexists (nmm_strAttachFilePath) then
Tidattachment (nmg_msgBody.MessageParts.Items [nmm_index]). SaveToFile (nmm_strAttachFilePath );
Except
Continue;
End;
// ************************** Replace the image src ********** ******
Nmg_Reg.Expression: = 'src \ s * = \ s *"? [^ \ S] * @ [^ \ s] * "? ';
Nmm_strbody: = nmg_stsContent.text;
If nmg_reg.Exec (nmm_strbody) then
Begin
Nmm_strbody: = StringReplace (nmm_strbody, nmg_reg.Match [0],
'Src = '+ nmm_strAttachFileUrl, [rfReplaceAll, rfIgnoreCase]);
Nmg_stsContent.Text: = nmm_strbody;
End;
//************************************** **************
End;
End;
End;
If nmg_blnHasAttOut = true then FinishAttachHtm (nmm_strDirName + '\ mailatt.htm ');
FinishContentHtm (nmm_strDirName + '\ mailcont.htm ');
****** ******************************
Nmg_reRunTimeErr: = reSuccess;
Nmg_arrAllErrString [Ord (reGetReceiveErr)]: = 'Received the specified email successfully .';
Except
On e: Exception do
Begin
Result: = '';
Nmg_reRunTimeErr: = reGetReceiveErr;
Nmg_arrAllErrString [Ord (nmg_reRunTimeErr)]: = E. Message;
End;
End;
Result: = nmg_reRunTimeErr;
End;

Thank you! I'll study it first.

To: zuoansuifeng. The code of the following functions in your code can be used again.
FormAttachHtm, DecodeHeader, FinishAttachHtm, FinishContentHtm, nmg_stsAttach
Thank you first

Zuoansuifeng good guy

I have done it myself.
But thanks to zuoansuifeng (Left Bank)

Split and pasted

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.