Forward message without loading


#1

Is it possible to forward a message without opening it first with MailMessage? It sometimes raises out of memory exception for us.


#2

@PeterNat,

Yes, this is possible using the SmtpClient of the API. Please have a look at the following code sample for your reference. The same is available in Aspose.Email documentation.

Sample Code

string host = "mail.server.com";
string username = "username";
string password = "password";
int smtpPort = 587;
string sender = "Sender@domain.com";
MailAddressCollection recipients = new MailAddressCollection();
recipients.Add("recepient1@domain.com, recepient2@domain.com");

using (SmtpClient client = new SmtpClient(host, smtpPort, username, password, SecurityOptions.Auto))
{
    string fileName = @"test.eml";
    using (FileStream fs = File.OpenRead(dataDir + fileName))
    {
        client.Forward(sender, recipients, fs);
    }
}