During the sending or receiving of messages (.eml), the memory usage is very high.
For example, for a 100MB file, the memory used by the process reaches 1.6GB.
public async Task SendMailWithLargeAttachTest()
{
/* Path to Aspose License */
const string ASPOSE_LIC_PATH = "ASPOSE_LIC_PATH";
/* SMTP client configuration */
const string host = "localhost";
const int port = 465;
const string username = "username";
const string password = "password";
/* test mail data */
const string from = "addressFrom";
const string to = "toAddress";
/* temporary path */
const string tmpPath = "tmpPath";
new License().SetLicense(ASPOSE_LIC_PATH);
string attachPath = Path.Combine(tmpPath, "file100M.txt");
try
{
using (var msg = new MailMessage(from, to)
{
Subject = "Test File100M"
})
{
using (var fs = new FileStream(attachPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
{
fs.SetLength(100 * 1024 * 1024);
await fs.FlushAsync();
fs.Position = 0;
msg.AddAttachment(new Attachment(fs, Path.GetFileName(attachPath)));
using (var smtpClient = new Aspose.Email.Clients.Smtp.SmtpClient(host, port, username, password))
{
smtpClient.SucceededSending += (sender, eventArgs) => Console.WriteLine(eventArgs.Message);
smtpClient.FailedSending += (sender, eventArgs) => Console.WriteLine(eventArgs.OperationError.Message, eventArgs.OperationError.StackTrace);
await smtpClient.SendAsync(msg);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}