**Bug with MailMessage**

  • Thread starter Thread starter Lee Alexander
  • Start date Start date
L

Lee Alexander

Hi,

There seems to be a bug with sending mail using SmtpMail.Send. If you send
an email using an SMTP server having an attachment with no body filled in
then the attachment gets corrupted on the recieving end (I attached a pdf
file). Find the code I used below. Note you will have to change the server
email addresses etc...

using System;
using System.Web.Mail;

namespace SendMail
{
class Class1
{
[STAThread]
static int Main(string[] args)
{
MailMessage message = new MailMessage();
message.Body = null;
message.Attachments.Add( new MailAttachment(@"d:\SomePDF.pdf",
MailEncoding.Base64 ));
message.Subject = "test";
message.From = (e-mail address removed);
message.To = "(e-mail address removed)";
SmtpMail.SmtpServer = "Some SMTP server";
SmtpMail.Send( message );
return 0;
}
}
}

P.S don't forget to include a reference to System.Web.dll otherwise it won't
compile.

If you want this example to work then you need to change 'message.Body =
null' to 'message.Body = String.Empty'.

Seems like a bug to me....

Regards
Lee
 
Lee Alexander said:
Hi,

There seems to be a bug with sending mail using SmtpMail.Send. If you send
an email using an SMTP server having an attachment with no body filled in
then the attachment gets corrupted on the recieving end (I attached a pdf
file). Find the code I used below. Note you will have to change the server
email addresses etc...

using System;
using System.Web.Mail;

namespace SendMail
{
class Class1
{
[STAThread]
static int Main(string[] args)
{
MailMessage message = new MailMessage();
message.Body = null;
message.Attachments.Add( new MailAttachment(@"d:\SomePDF.pdf",
MailEncoding.Base64 ));
message.Subject = "test";
message.From = (e-mail address removed);
message.To = "(e-mail address removed)";
SmtpMail.SmtpServer = "Some SMTP server";
SmtpMail.Send( message );
return 0;
}
}
}

P.S don't forget to include a reference to System.Web.dll otherwise it won't
compile.

If you want this example to work then you need to change 'message.Body =
null' to 'message.Body = String.Empty'.

Seems like a bug to me....

Regards
Lee

Thanks for the report. I've filed a bug and it will hopefully be
fixed in the next release. I'm glad you found a workaround though.
 
Thanks for the report. I've filed a bug and it will hopefully be
ok
fixed in the next release. I'm glad you found a workaround though.
Me too :-)
Nick Hertl said:
"Lee Alexander" <lee@No_Spam_Please_Digita.com> wrote in message
Hi,

There seems to be a bug with sending mail using SmtpMail.Send. If you send
an email using an SMTP server having an attachment with no body filled in
then the attachment gets corrupted on the recieving end (I attached a pdf
file). Find the code I used below. Note you will have to change the server
email addresses etc...

using System;
using System.Web.Mail;

namespace SendMail
{
class Class1
{
[STAThread]
static int Main(string[] args)
{
MailMessage message = new MailMessage();
message.Body = null;
message.Attachments.Add( new MailAttachment(@"d:\SomePDF.pdf",
MailEncoding.Base64 ));
message.Subject = "test";
message.From = (e-mail address removed);
message.To = "(e-mail address removed)";
SmtpMail.SmtpServer = "Some SMTP server";
SmtpMail.Send( message );
return 0;
}
}
}

P.S don't forget to include a reference to System.Web.dll otherwise it won't
compile.

If you want this example to work then you need to change 'message.Body =
null' to 'message.Body = String.Empty'.

Seems like a bug to me....

Regards
Lee

Thanks for the report. I've filed a bug and it will hopefully be
fixed in the next release. I'm glad you found a workaround though.
 
Back
Top