Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JMAIL - delete emails / rename attachments

Status
Not open for further replies.

williamsba

Programmer
Joined
Aug 3, 2000
Messages
57
Location
US
Hello,

I am working on a script using the JMail component. Right now I've made it so it logs in to my pop mail account, grabs all of the attachments it finds, and saves them to my web server. That all works just fine. What I am trying to figure out is two things:

1. How can I delete the email after I am done with it

2. How can I rename the file attachment before saving it to my web server

I've search through the JMail manual, and many other sites with no luck on deleting or renaming the file. If this is not possible can anyone suggest a different route to take on this? Thanks

Brad Williams
Webmaster

 
dunno about deleting the email, i dont know much about JMAIL

you can use FSO to make a copy of the file with the desired filename, attach it, send the mail, then using the same FSO object to delete the temp file
 
I'm not sending emails with JMail, I'm receiving emails in to my pop account. Reading the emails and downloading the attachments on to my web server. I could probably make the FSO work, but it would really be a pretty heafty work around.

Brad Williams
Webmaster

 
are you doing this thru asp pages?

does Jmail have a save attachment method?
 
Yes ASP. Yes I can save the attachments just fine, but I'm trying to figure out if it supports renaming. Here is my code:

<% @LANGUAGE=VBSCRIPT%>
<%
Set pop3 = Server.CreateObject( "JMail.POP3" )
pop3.Connect "email@mydomain.com", "password", "mail.mydomain.com"

Function getEmail(x)

if pop3.count > 0 then

Set msg = pop3.Messages.item(x)

' This function iterates through the Attachments object,
' and saves the attachment to the server's disk.
' It also returns a nicely formatted string with a
' link to the attachment.

Set Attachments = msg.Attachments
separator = ", "

For i = 0 To Attachments.Count - 1
If i = Attachments.Count - 1 Then
separator = ""
End If

Set at = Attachments(i)
If ( InStr(at.Name, "jpg") > 0 OR InStr(at.Name, "gif") > 0 ) Then
Randomize timer
randnum = int(rnd * 10000000)
filename = randnum
filename = filename & ".gif"
at.SaveToFile( "c:\directory\my\files\go\in\" & at.Name )
End if
Next

end if

End Function



x = pop3.count
DO UNTIL x = 0

getemail(x)

x = x - 1
Loop
pop3.Disconnect
%>

Keep in mind that this works fine, I just need to delete the emails after it saves their attachments, and then rename the attachment.

Brad Williams
Webmaster

 
at.SaveToFile( "c:\directory\my\files\go\in\" & at.Name )

that is the line where it saves it.

Brad Williams
Webmaster

 
ya what he said :)

filename = randnum <-- Change this to whatever filename you're wanting to use
filename = filename & ".gif"
at.SaveToFile( "c:\directory\my\files\go\in\" & at.Name ) <--- and at.Name should be filename
End if
Next
 
Change that causes an error. I went ahead and used FSO to rename the file:

If ( InStr(at.Name, "jpg") > 0 OR InStr(at.Name, "gif") > 0 ) Then
Randomize timer
randnum = int(rnd * 10000000)
filename = randnum
filename = filename & ".gif"
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
at.SaveToFile( "c:\directory\my\files\go\in\" & at.Name )
fso.MoveFile "c:\directory\my\files\go\in\" & at.Name, "c:\directory\my\files\go\in\" & filename
End if


Now I just have to figure out how to delete the email.

Brad Williams
Webmaster

 
Got it!

pop3.DeleteSingleMessage x


That isn't even in the manual!! Thanks for the help!

Brad Williams
Webmaster

 
:) and dont forget to close out your fso object, deleteting the email from the server or locally?
 
From the server

Brad Williams
Webmaster

 
i'd have to look at some jmail documentation, perhaps someone that has will jump in here, otherwise after some reading i'll post again
 
I fixed it already. Thanks anyways!

Brad Williams
Webmaster

 
as a beneficial thing to others that might come across a similar problem in the future, could you post the resolution in here?

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top