Board index » Visual Studio » A way to email files with if/then possible?

A way to email files with if/then possible?

Visual Studio202
I changed FROM to SUBJECT



That only moves all emails to the C:\email folder it does not creat

folder named after the subject. I dimmed the ON ERROR while tryin

that and get ERROR on line 19. Something to do with LEFT. I tried t

dim that out also :). Worth a try no luck. I undimmed the two extr

msg boxs and shows that they are moving the files and that the emai

folder is created but you can see that its not creating the subjec

folder, unsure of what the problem might be there.



As for the FROM's with all three msgboxs popping up it shows trying t

create three of three but only two where created. Two happened to b

the same email address except one came up as janedoe@exit.com and th

second came up as Jane Doe janedoe@exit.com



Hmm thats got me thinking now back to the script

Is the part of the scirpt with brakets is that to do with the emai

address, and the name before the email address? Having problems tryin

to post this message.



Is that part of the script looking for the name inside the <>brackets

Like i said i am trying to figure it out for myself a little bit, yo

have been a great help. Wish i knew more about this stuff.



You can get me on email if that would be easier at david@pccjuliet.net



Dav





-

XFait

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

Posted via www.codecomments.co

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


-
 

Re:A way to email files with if/then possible?

"XFaith"

Quote
I changed FROM to SUBJECT

That only moves all emails to the C:\email folder it does not create

folder named after the subject [...]





ON ERROR RESUME NEXT

sp = "c:\Email\"

Set oFSO = CreateObject("Scripting.FileSystemObject")

If Not (ofso.FolderExists(sp)) Then

ofso.CreateFolder(sp)

end if



sDirectory = "C:\Documenti\Bozze mail"

Set oFolder = oFSO.GetFolder(sDirectory)

For Each oFile In oFolder.Files

If InStr(UCase(oFile.Name), ".EML") Then

Set oStream = oFSO.OpenTextFile(oFile.Path, 1)

Do Until oStream.AtEndOfStream

sLine = oStream.ReadLine

If InStr(UCase(sLine),"SUBJECT:") Then



msgbox sline

' arg = Sline

' i2 = InStrRev(Arg, ">")

'Arg2 = Left(Arg, (i2 - 1))

'strTestString = arg2

'iPos = InStr(iPos + 1, strTestString, "<")

' iCnt = iCnt + 1

' strFirst = Left(strTestString, iPos)

strSecond = Mid(strTestString, iPos + 1)

SLine = Replace(sLine,":","_")

strSecond = sLine&"\"

' msgbox oFile.Path

' msgbox sp&strSecond

path = sp&strSecond

If not ofso.FolderExists(ofso.GetParentFolderName(Path)) Then

Call CreateFolderPath(ofso.GetParentFolderName(Path))

End If

Set CreateFolderPath = ofso.CreateFolder(Path)

oFSO.CopyFile oFile.Path, sp&strSecond, True

End If

Loop

End If

Next



msgbox "done"





--

Fosco



-

Re:A way to email files with if/then possible?

"XFaith"

Quote
Is that part of the script looking for the name inside the <>brackets?



YES .. try the modified script .. the ouput will look like this :



C:\Email\Subject_ Returned mail_ User unknown

with

C:\Email\Subject_ Returned mail_ User unknown\Returned mail_ User unknown.eml

inside



C:\Email\Subject_ sport2

with

C:\Email\Subject_ sport2\sport calcio 2.eml

C:\Email\Subject_ sport2\sport calcio 3.eml



ecc



--

Fosco

-

Re:A way to email files with if/then possible?

"XFaith"

Quote
I changed FROM to SUBJECT:



or FORM:



Hint>>watch for illegale characters

Windows will NEVER create such a Folder :

<tinitfree@tin.it>

or

Subject: Arriva la tua Chiave Unica!



\ /:*?"<>| are not allowed in folder names



--

Fosco





-

Re:A way to email files with if/then possible?

"Fosco"

Quote
\ /:*?"<>| are not allowed in folder names



'other way to avoid this :

' reason .. split/parse/trim strings is not so simple

' escape the strings is real one click affair and you don't

' have to bother on it



ON ERROR RESUME NEXT

sp = "c:\Email\"

Set oFSO = CreateObject("Scripting.FileSystemObject")

If Not (ofso.FolderExists(sp)) Then

ofso.CreateFolder(sp)

end if



sDirectory = "C:\Documenti\Bozze mail"

Set oFolder = oFSO.GetFolder(sDirectory)

For Each oFile In oFolder.Files

If InStr(UCase(oFile.Name), ".EML") Then

Set oStream = oFSO.OpenTextFile(oFile.Path, 1)

Do Until oStream.AtEndOfStream

sLine = oStream.ReadLine

If InStr(UCase(sLine),"SUBJECT:") Then



sline = escape( sline) ' [1]

msgbox sline

strSecond = Mid(strTestString, iPos + 1)

SLine = Replace(sLine,":","_")

strSecond = sLine&"\"

' msgbox oFile.Path

' msgbox sp&strSecond

path = sp&strSecond

If not ofso.FolderExists(ofso.GetParentFolderName(Path)) Then

Call CreateFolderPath(ofso.GetParentFolderName(Path))

End If

Set CreateFolderPath = ofso.CreateFolder(Path)

oFSO.CopyFile oFile.Path, sp&strSecond, True

End If

Loop

End If

Next



msgbox "done"



'[1]



'It is not documented in the WSH help docs, but the "escape" function has

'been part of the core of VBScript for a few versions. If you do a



'wscript.echo escape(somestring)



'it will escape any characters which are not "HTML-safe", including all

'nonprinting characters such as tabs, spaces, and line feeds. You can

'use this to tell what the actual character count and type is. They will

'be displayed as %-prefixed hex numbers corresponding to their character

'value.

'For example, vbCrLf, which is Chr(13) & Chr(10), will be displayed in an

'escaped string as '%0D%0A



--

Fosco













-

Re:A way to email files with if/then possible?

"Fosco"

Quote
\ /:*?"<>| are not allowed in folder names



'other way to avoid this :

' reason .. split/parse/trim strings is not so simple

' escape the strings is real one click affair and you don't

' have to bother on it



ON ERROR RESUME NEXT

sp = "c:\Email\"

Set oFSO = CreateObject("Scripting.FileSystemObject")

If Not (ofso.FolderExists(sp)) Then

ofso.CreateFolder(sp)

end if



sDirectory = "C:\Documenti\Bozze mail"

Set oFolder = oFSO.GetFolder(sDirectory)

For Each oFile In oFolder.Files

If InStr(UCase(oFile.Name), ".EML") Then

Set oStream = oFSO.OpenTextFile(oFile.Path, 1)

Do Until oStream.AtEndOfStream

sLine = oStream.ReadLine

If InStr(UCase(sLine),"SUBJECT:") Then



sline = escape( sline) ' [1]

msgbox sline

strSecond = Mid(strTestString, iPos + 1)

SLine = Replace(sLine,":","_")

strSecond = sLine&"\"

' msgbox oFile.Path

' msgbox sp&strSecond

path = sp&strSecond

If not ofso.FolderExists(ofso.GetParentFolderName(Path)) Then

Call CreateFolderPath(ofso.GetParentFolderName(Path))

End If

Set CreateFolderPath = ofso.CreateFolder(Path)

oFSO.CopyFile oFile.Path, sp&strSecond, True

End If

Loop

End If

Next



msgbox "done"



'[1]



'It is not documented in the WSH help docs, but the "escape" function has

'been part of the core of VBScript for a few versions. If you do a



'wscript.echo escape(somestring)



'it will escape any characters which are not "HTML-safe", including all

'nonprinting characters such as tabs, spaces, and line feeds. You can

'use this to tell what the actual character count and type is. They will

'be displayed as %-prefixed hex numbers corresponding to their character

'value.

'For example, vbCrLf, which is Chr(13) & Chr(10), will be displayed in an

'escaped string as '%0D%0A



--

Fosco









-