Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET POP3

 AfterLogic Forum : MailBee.NET POP3
Subject Topic: Saving Attachment issues..... Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
zcast
Newbie
Newbie
Avatar

Joined: 10 July 2011
Location: United States
Online Status: Offline
Posts: 15
Posted: 15 July 2011 at 10:07am | IP Logged Quote zcast

Using the example file "POP3 DEMO2", can someone please tell me why the code that saves attachments works perfectly fine in the first sub, but not the btn click event?

Works fine....

    Public Sub New(ByVal msg As MailMessage)
        'This call is required by the Windows Form Designer.
        InitializeComponent()

        ' For HTML message, display plain-text version,
        ' for plain-text message, display the plain-text itself.
        ' HtmlToPlainMode needs to be set BEFORE we access message fields
        ' (body, headers, attachments, etc) because the message gets parsed
        ' when we access any of its parts first time, and HTML to plain-text
        ' conversion takes place during parsing. Thus, we need to tell MailBee that
        ' we wish to get plain-text version of HTML-only mail BEFORE parsing occurs.
        msg.Parser.HtmlToPlainMode = HtmlToPlainAutoConvert.IfNoPlain

        ' Display message headers.
        textBoxFrom.Text = msg.From.AsString
        textBoxTo.Text = msg.To.AsString
        textBoxSubject.Text = msg.Subject

        ' Display plain-text body.
        textBoxBody.Text = msg.BodyPlainText

        ' Display attachments.
        textBoxAttachments.Text = String.Empty

        ' Display filenames of the attachments
        Dim attach As Attachment
        For Each attach In msg.Attachments
            ' Show unique file name of the attachment.
            textBoxAttachments.Text &= attach.Filename & "; "
          msg.Attachments.SaveAll(My.Settings.SaveAttachmentDir, True)
        Next
    End Sub


Doesn't work at all.....

Public Sub btnSaveMessage_Click(sender As System.Object, e As System.EventArgs) Handles btnSaveMessage.Click
        Try

            Dim attach As Attachment
            For Each attach In msg.Attachments
               ' Show unique file name of the attachment.
               'textBoxAttachments.Text &= attach.Filename & "; "
               msg.Attachments.SaveAll(My.Settings.SaveAttachmentDir, True)
            Next
        Catch ex As Exception

        End Try
    End Sub

The second code is the next sub down, on the same form. What have I missed???
Back to Top View zcast's Profile Search for other posts by zcast
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 15 July 2011 at 10:18am | IP Logged Quote Alex

"Doesn't work at all" isn't clear enough. Which exception is thrown? What exactly happens? And so on.

Also, I don't understand why msg.Attachments.SaveAll occurs in For Each. It's enough to have it called only once for a message.

And I don't understand why you catch all exceptions but don't handle them (in second example).

I even don't see msg variable being declared in the second code.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
zcast
Newbie
Newbie
Avatar

Joined: 10 July 2011
Location: United States
Online Status: Offline
Posts: 15
Posted: 15 July 2011 at 10:29am | IP Logged Quote zcast

I'm sorry Alex for not being clearer in my explanation. "Doesn't work" means the btn click does not save the attachments to my specified directory. I have removed the "save all" statement from the "for each", and I NORMALLY do handle each exception, just simply missed that one, but NO error messages are being returned with this updated code, but yet the attachments are being saved still.

Public Sub btnSaveMessage_Click(sender As System.Object, e As System.EventArgs) Handles btnSaveMessage.Click
        Try
            Dim msg As MailMessage
            Dim attach As Attachment
            For Each attach In msg.Attachments
               ' Show unique file name of the attachment.
               textBoxAttachments.Text &= attach.Filename & "; "
               'Next
            Next
           
            msg.Attachments.SaveAll(My.Settings.SaveAttachmentDir, True)

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
Back to Top View zcast's Profile Search for other posts by zcast
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 15 July 2011 at 11:17am | IP Logged Quote Alex

Do you have any attachments at all? I see you declare msg variable but it does not get assigned anywhere.

It's not clear what's in textBoxAttachments.Text value.

Also, .SaveAll(path, ignoreInlineAttachments=True) does not save inline attachments.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
zcast
Newbie
Newbie
Avatar

Joined: 10 July 2011
Location: United States
Online Status: Offline
Posts: 15
Posted: 15 July 2011 at 12:34pm | IP Logged Quote zcast

Yes, there is one file as an attachment. In this subroutine, the attachment gets saved perfectly to the desginated folder.

Public Sub New(ByVal msg As MailMessage)
        'This call is required by the Windows Form Designer.
        InitializeComponent()

        ' For HTML message, display plain-text version,
        ' for plain-text message, display the plain-text itself.
        ' HtmlToPlainMode needs to be set BEFORE we access message fields
        ' (body, headers, attachments, etc) because the message gets parsed
        ' when we access any of its parts first time, and HTML to plain-text
        ' conversion takes place during parsing. Thus, we need to tell MailBee that
        ' we wish to get plain-text version of HTML-only mail BEFORE parsing occurs.
        msg.Parser.HtmlToPlainMode = HtmlToPlainAutoConvert.IfNoPlain

        ' Display message headers.
        textBoxFrom.Text = msg.From.AsString
        textBoxTo.Text = msg.To.AsString
        textBoxSubject.Text = msg.Subject

        ' Display plain-text body.
        textBoxBody.Text = msg.BodyPlainText

        ' Display attachments.
        textBoxAttachments.Text = String.Empty

        ' Display filenames of the attachments
        Dim attach As Attachment
        For Each attach In msg.Attachments
            ' Show unique file name of the attachment.
            textBoxAttachments.Text &= attach.Filename & "; "
          [b]msg.Attachments.SaveAll(My.Settings.SaveAttachmentDir, True)[/b]
        Next
    End Sub


but using this section of the code above in a btn click event does nothing:


Public Sub btnSaveMessage_Click(sender As System.Object, e As System.EventArgs) Handles btnSaveMessage.Click
        Try
        Dim attach As Attachment
        For Each attach In msg.Attachments
            ' Show unique file name of the attachment.
            textBoxAttachments.Text &= attach.Filename & "; "
          [b]msg.Attachments.SaveAll(My.Settings.SaveAttachmentDir, True)[/b]
        Catch ex As Exception
          msgbox(ex.Message)
        Next
    End Sub
No attachments are saved whether it'd set to true or false, and No errors occur.
Back to Top View zcast's Profile Search for other posts by zcast
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 15 July 2011 at 2:32pm | IP Logged Quote Alex

Again, I don't even see msg variable in the second routine. It does not get passed in the parameters.

And you didn't answer what in textBoxAttachments.Text value in the second case.

To let us help you, please make sure you clearly answer all the questions.

How do you know it's the same msg that is in the first routine.

Have you ever tried to debug your code? I.e. set a breakpoint in your code to make sure msg.Attachments.SaveAll gets called at all, to check the value of msg.Attachments.Count (so that it's not zero), etc.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
zcast
Newbie
Newbie
Avatar

Joined: 10 July 2011
Location: United States
Online Status: Offline
Posts: 15
Posted: 15 July 2011 at 4:01pm | IP Logged Quote zcast

Ok, better yet, I'll make this easy--How do I go about saving an attachment from the displayed message? (There IS an attachment called demo.pdf in nthe attachments textbox)
Back to Top View zcast's Profile Search for other posts by zcast
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 16 July 2011 at 2:30am | IP Logged Quote Alex

At the end of "Public Sub New(ByVal msg As MailMessage)" in POP3Demo2, insert
"msg.Attachments.SaveAll(My.Settings.SaveAttachmentDir, False) " (not in For Each, however).

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 16 July 2011 at 2:35am | IP Logged Quote Alex

Of course, if you need to do the same in another routine, you'll need to know how to work with variables, and so on (as in the POP3Demo2 sample msg variable is only passed to Public Sub New constructor and never saved in the class's internal variable) but this is out of the scope of using MailBee.NET, it's a more general question of how to do programming in VB.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
halwits2011
Newbie
Newbie


Joined: 22 September 2011
Location: India
Online Status: Offline
Posts: 5
Posted: 22 September 2011 at 10:40pm | IP Logged Quote halwits2011

I think its a better way to described this concept so thanks for share with me and we can easily design with us and more supported for us.
Back to Top View halwits2011's Profile Search for other posts by halwits2011
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide