0 votes
by (120 points)

Can you advise what location is used when an attachment is saved.

I am downloading an eamil as per the POP3 Tutorial, and it has 1 attachment (a PDF file).

I then follow the Extract Attachments sample to save the attachment.

The code executes cleanly, but I can't locate the saved file.

VB code snippet is

Do While sequenceNumber <= list.Count
     message = client.GetMailMessage(list(0).SequenceNumber)
     Dim attachments As Integer = _message.Attachments.Count
     If attachments > 0 Then
            Dim attachment As Rebex.Mail.Attachment
            For Each attachment In _message.Attachments
            Next attachment
     End If

I'm using the trail version downloaded 04/08/12 and VisualStudio 2005, Windows 7 up to date

Thank you in anticipation

Clive Prescott

Applies to: Rebex Secure Mail

1 Answer

0 votes
by (18.0k points)

An argument of the Attachment.Save method is a path to the file to write the content to. If you specify just the filename (without a path), the attachment will be written usually to the directory your application has been executed from.

Anyway, I'd recommend you to specify a full path e.g. following way:

Dim outputPath As String = "c:\temp"
attachment.Save(System.IO.Path.Combine(outputPath, attachment.FileName))

Additional comments:

In your example above, you have a typo (maybe intentional, for debug purposes). In the following line:

 message = client.GetMailMessage(list(0).SequenceNumber)

you will always obtain the oldest message from the list only (with a 0 index). You should replace it with:

 message = client.GetMailMessage(list(sequenceNumber).SequenceNumber)

And please note that the sequenceNumber variable holds something different than the SequenceNumber property of POP3 messages. The variable is just an index in the list collection and the collection is indexed from 0 to (SequenceNumber-1).

So the whole code should look like this:

    Dim client = New Pop3()
    ' specify connection data for your server'
    client.Login("username", "password")
    ' specify path on your computer, where the atachments should be written to' 
    Dim outputPath = "c:\temp"

    Dim list = client.GetMessageList()

    Dim i = 0
    While i < list.Count
        Dim message = client.GetMailMessage(list(i).SequenceNumber)
        For Each attachment In message.Attachments
            attachment.Save(System.IO.Path.Combine(outputPath, attachment.FileName))
        Next attachment
        i = i + 1
    End While