Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Receive email with attachment in VFP
Message
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01544911
Message ID:
01545756
Views:
76
This code is used to parse emails already downloaded by http://www.berezniker.com/content/pages/visual-foxpro/read-pop3-mail-using-winsock.

toObj is not required. You can create an object to return inside
*loMail = toObj
loMail = CREATEOBJECT("Empty")
Keep in mind that code only retrieves attachment names. Let me know if you have a problem with retrieving attachments.

>I just started working on trying to apply your code (for CDO 2000) into my program but can't understand a couple of basic things. What are the parameters, FileName, and the object (toObj)? Also, I don't see anywhere in the code where to specify the incoming mail server, email address, and user name and password. Are these values outside of this code?
>
>Thank you.
>
>>
>>
>>
>>LPARAMETERS tcFileName, toObj
>>
>>LOCAL loStm AS ADODB.Stream, loMsg AS CDO.Message, loDsrc AS loMsg.DataSource
>>LOCAL loMail, oErr AS Exception, lcFileName, lnX, loMsgAttached, lcHeader
>>
>>
>>lcFileName = ALLTRIM(tcFileName)
>>
>>loMail = toObj
>>
>>
>>=ADDPROPERTY(loMail, "Created_dt",{// ::})
>>=ADDPROPERTY(loMail, "Emailtype","")
>>=ADDPROPERTY(loMail, "Subject","")
>>=ADDPROPERTY(loMail, "Toaddr","")
>>=ADDPROPERTY(loMail, "Sent_dt",{//,:})
>>=ADDPROPERTY(loMail, "Textbody","")
>>=ADDPROPERTY(loMail, "Htmlbody","")
>>=ADDPROPERTY(loMail, "Attachment","")
>>=ADDPROPERTY(loMail, "Fromaddr","")
>>=ADDPROPERTY(loMail, "Replyto","")
>>=ADDPROPERTY(loMail, "Cc","")
>>=ADDPROPERTY(loMail, "Bcc","")
>>=ADDPROPERTY(loMail, "Fullmessag","")
>>=ADDPROPERTY(loMail, "Created_by","")
>>=ADDPROPERTY(loMail, "Ref_Id",0)
>>
>>=ADDPROPERTY(loMail, "lError", .F.)
>>=ADDPROPERTY(loMail, "cErrorMessage", "")
>>
>>IF NOT FILE(lcFileName)
>>	loMail.lError = .T.
>>	loMail.cErrorMessage = "File '" + lcFileName + "' doesn't exists."
>>	RETURN loMail
>>ENDIF
>>
>>lcFileName = FULLPATH(lcFileName)
>>
>>loStm = CREATEOBJECT("ADODB.Stream")
>>loMsg = CREATEOBJECT("CDO.Message")
>>
>>TRY
>>	loStm.Open()
>>	loStm.LoadFromFile(lcFileName)
>>	loDsrc = loMsg.DataSource
>>	loDsrc.OpenObject(loStm, "_Stream")
>>
>>	lcHeader = lcCrLf + REPLICATE("-", 20) + lcCrLf
>>	FOR lnX=1 TO loMsg.Attachments.Count
>>		IF NOT (loMsg.Attachments[lnX].ContentMediaType = "message/rfc822")
>>			*? lnX, loMsg.Attachments[lnX].ContentMediaType
>>			loMail.Attachment = loMail.Attachment + ;
>>					IIF( EMPTY(loMail.Attachment), [], [,]) + ;
>>					loMsg.Attachments[lnX].FileName 
>>			LOOP
>>		ENDIF
>>		loMsgAttached = CREATEOBJECT("CDO.Message")
>>		loMsgAttached.DataSource.OpenObject(loMsg.Attachments[lnX].GetDecodedContentStream(), "_Stream")
>>		lcHeader = lcHeader + "From: " + loMsgAttached.From + lcCrLf
>>		lcHeader = lcHeader + "Sent: " + TTOC(loMsgAttached.SentOn) + lcCrLf
>>		lcHeader = lcHeader + "To: " + loMsgAttached.To + lcCrLf
>>		lcHeader = lcHeader + "Subject: " + loMsgAttached.Subject + lcCrLf
>>		lcHeader = lcHeader + lcCrLf + lcCrLf + lcCrLf
>>		loMsg.TextBody = loMsg.TextBody + lcHeader + loMsgAttached.TextBody 
>>		IF NOT EMPTY(loMsgAttached.HtmlBody)
>>			loMsg.HtmlBody = loMsg.HtmlBody + STRTRAN(lcHeader, lcCrLf, "<br>") + loMsgAttached.HtmlBody
>>		ENDIF	
>>		loMsgAttached = Null
>>	ENDFOR
>>CATCH TO oErr
>>	loMail.lError = .T.
>>	loMail.cErrorMessage = oErr.Message
>>ENDTRY
>>
>>WITH loMail
>>	.FullMessag = FILETOSTR(lcFileName)
>>	.Created_Dt = DATETIME()
>>	.Sent_dt = loMsg.SentOn
>>	.Subject = loMsg.Subject
>>	.ToAddr = loMsg.To
>>	.TextBody = loMsg.TextBody
>>	.HtmlBody = loMsg.HtmlBody
>>	*.Attachment = loMsg.Attacments
>>	.FromAddr = loMsg.From
>>	*.Replyto = loMsg.Replyto
>>	.CC = loMsg.CC
>>	.BCC = loMsg.BCC
>>ENDWITH
>>
>>
>>RETURN loMail
>>
>>
>>>Although I don't even know what CDO 2000 is and therefore don't know if it is applicable to my application, I would like to see the code. Thank you.
>>>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform