PowerTCP Mail for .NET
Save(String) Method
Example 




The file location where the encoded message will be saved.
Encodes the MailMessage and saves it to the specified location.
Syntax
Public Overloads Sub Save( _
   ByVal filePath As String _
) 
Dim instance As MailMessage
Dim filePath As String
 
instance.Save(filePath)
public void Save( 
   string filePath
)
public: void Save( 
   string* filePath
) 
public:
void Save( 
   String^ filePath
) 

Parameters

filePath
The file location where the encoded message will be saved.
Exceptions
ExceptionDescription
System.UnauthorizedAccessExceptionThis often indicates that an antivirus has quarantined or blocked access to a decoded attachment on disk. Set DecodeToMemory to true to decode attachments to memory instead of to disk to circumvent your antivirus. Alternatively, test each attachment with Attachment.Content.OpenRead() and remove any attachments that throw an exception.
System.IO.FileNotFoundExceptionThis often indicates that an antivirus has quarantined or blocked access to a decoded attachment on disk. Set DecodeToMemory to true to decode attachments to memory instead of to disk to circumvent your antivirus. Alternatively, test each attachment with Attachment.Content.OpenRead() and remove any attachments that throw an exception.
Remarks

Any existing file will be overwritten.

Saving a MailMessage with this method will include the Bcc field, which should not be included in messages sent to a server. To output the MailMessage as it would be sent to a server, use MailMessage.GetEncodingStream().

Example
In this example, messages are retrieved with the Pop component then saved to disk.
private void getMessages(object sender)
{
    //Connect and log into the account
    pop1.Connect();
    pop1.Authenticate(true, true);

    //Download all messages in the account and save them to disk with a unique name
    string messageFolder = Application.StartupPath + "\\messages";
    foreach (PopMessage popMessage in pop1.Messages)
    {
        popMessage.Get();
        popMessage.Message.Save(messageFolder + "\\" + popMessage.Id.ToString("D4") + ".eml");
    }

    //Gracefully logout of the session
    pop1.Close();
}

private void pop1_Progress(object sender, PopProgressEventArgs e)
{
    //Update progress bar as messages are received
    progressBar1.Value = (e.Final) ? 0 : (int)((e.Position * 100) / e.Length);
}
Private Sub getMessages(ByVal sender As Object)
    'Connect and log into the account
    pop1.Connect()
    pop1.Authenticate(True, True)

    'Download all messages in the account and save them to disk with a unique name
    Dim messageFolder As String = Application.StartupPath & "\messages"
    For Each popMessage As PopMessage In pop1.Messages
        popMessage.Get()
        popMessage.Message.Save(messageFolder & "\" & popMessage.Id.ToString("D4") & ".eml")
    Next popMessage

    'Gracefully logout of the session
    pop1.Close()
End Sub

Private Sub pop1_Progress(ByVal sender As Object, ByVal e As PopProgressEventArgs) Handles pop1.Progress
    'Update progress bar as messages are received
    progressBar1.Value = If(e.Final, 0, CInt((e.Position * 100) \ e.Length))
End Sub
See Also

Reference

MailMessage Class
MailMessage Members
Overload List


PowerTCP Mail for .NET Documentation Version 4.3
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic