Saves the attachment to a local file.
[Visual Basic 6.0] Public Sub SaveAs( _ FileName As String, _ Overwrite As Boolean _ )
[Visual C++] public: HRESULT SaveAs( BSTR* FileName, VARIANT_BOOL Overwrite );
Parameters
Example
[Visual Basic 6.0, VBScript, Visual C++] To get the full samples of EAGetMail, please refer to Samples section.
[Visual Basic 6.0] Private Sub ParseAttachment() On Error GoTo ErrorHandle Dim oMail As New EAGetMailObjLib.Mail Dim oTools As New EAGetMailObjLib.Tools oMail.LicenseCode = "TryIt" oMail.LoadFile "c:\test.eml", False Dim tempFolder As String tempFolder = "c:\temp" ' Decode winmail.dat (TNEF) automatically' oMail.DecodeTNEF If Not oTools.ExistFile(tempFolder) Then oTools.CreateFolder (tempFolder) End If Dim i, atts Set atts = oMail.AttachmentList For i = 0 To atts.Count - 1 Dim att As Attachment Set att = atts.Item(i) Dim attname attname = tempFolder & "\" & att.Name att.SaveAs attname, True Next Exit Sub ErrorHandle: MsgBox Err.Description End Sub
[VBScript] Sub ParseAttachment() Dim oMail Set oMail = CreateObject("EAGetMailObj.Mail") Dim oTools Set oTools = CreateObject("EAGetMailObj.Tools") oMail.LicenseCode = "TryIt" oMail.LoadFile "c:\test.eml", False Dim tempFolder tempFolder = "c:\temp" ' Decode winmail.dat (TNEF) automatically oMail.DecodeTNEF Dim i, atts Set atts = oMail.AttachmentList If Not oTools.ExistFile(tempFolder) Then oTools.CreateFolder (tempFolder) End If For i = 0 To atts.Count - 1 Dim att Set att = atts.Item(i) Dim attname attname = tempFolder & "\" & att.Name att.SaveAs attname, True Next End Sub
[Visual C++] //if you do not use MFC, please add this line to support CString type. #include <atlstr.h> #include "eagetmailobj.tlh" using namespace EAGetMailObjLib; void ParseAttachment() { IMailPtr oMail = NULL; CString tempFolder = _T("c:\\temp"); try { oMail.CreateInstance(__uuidof(EAGetMailObjLib::Mail)); oMail->LicenseCode = _T("TryIt"); oMail->LoadFile(_T("c:\\test.eml"), VARIANT_FALSE); // Decode winmail.dat (TNEF) automatically oMail->DecodeTNEF(); IAttachmentCollectionPtr attachments = oMail->AttachmentList; ::CreateDirectory(tempFolder.GetString(), NULL); for(long i = 0; i < attachments->Count; i++) { IAttachmentPtr pAtt = attachments->GetItem(i); CString name = (TCHAR*)pAtt->Name; CString attname = tempFolder; attname.Append(_T("\\")); attname.Append((TCHAR*)pAtt->Name); pAtt->SaveAs(attname.GetString(), VARIANT_TRUE); } } catch(_com_error &ep) { MessageBox(NULL, (TCHAR*)ep.Description(), _T("Error"), MB_OK); } }
[Delphi] procedure ParseAttachment(); Var oMail: TMail; i: Integer; atts: IAttachmentCollection; att: IAttachment; begin oMail := TMail.Create(Application); oMail.LicenseCode := 'TryIt'; oMail.LoadFile('c:\test.eml', false); // Decode winmail.dat (TNEF) automatically oMail.DecodeTNEF(); atts := oMail.AttachmentList; for i := 0 To atts.Count - 1 do begin att := atts.Item[i]; ShowMessage(att.Name); att.SaveAs('c:\tempfolder\' + att.Name, true); end; end;
See Also
Mail.AttachmentList Property
Mail.Attachments Property
Online Tutorials
Parse Email in VB6 - Tutorial
Parse winmail.dat(TNEF) in VB6 - Tutorial
Parse Email in Delphi - Tutorial
Parse winmail.dat(TNEF) in Delphi - Tutorial
Parse Email in VC++ - Tutorial
Parse winmail.dat(TNEF) in VC++ - Tutorial