0

I'm using FluentFtp and SmtpClient to get a file and attach it directly to an email, but the content of the attached file is empty.

Getting file:

public Stream GetFileStream()
{
  client = new FtpClient("123.123.123.123", "user", "pass");
  client.AutoConnect();

  Stream stream = new MemoryStream();
  client.DownloadStream(stream,"remotepath");
  return stream;
}

Sending mail function

public void SendMail(Stream file)
{
  var smtpClient = new SmtpClient("smtp-mail.outlook.com")
  {
    Port = 587,
    Credentials = new NetworkCredential("send@test.com", "password"),
    EnableSsl = true,
  };

  var message = new MailMessage()
  {
    From = new MailAddress("send@test.com"),
    Subject = "Test",
    Body = "Test",
    IsBodyHtml= true,
  };

  message.To.Add("receive@test.com");

  var attachment = new Attachment(file, "test.txt");
  message.Attachments.Add(attachment);

  smtpClient.Send(message);
}

I have relied on Attach file existing on FTP server to mail in C# .NET to send attachments, but I am not getting it.

Aritzbn
  • 174
  • 3
  • 18
  • You didn't show us how your two code snippets work together. Anyway, I assume you have this problem: [Transferring a file from FTP to Azure cloud via local MemoryStream buffer results in an 'empty' file](https://stackoverflow.com/q/61576831/850848). If not, we need [mcve]. – Martin Prikryl Apr 13 '23 at 11:49
  • @MartinPrikryl I think there's a minimal reproducible example alredy... there are just two functions, the first one returns the stream, the second one receives as parameter... the DLLs I'm using are on the post. Will check your link. – Aritzbn Apr 14 '23 at 07:14

0 Answers0