**Bug with MailMessage**

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
 
N

Nick Hertl

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.
 
L

Lee Alexander

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Mail Send Problems 1
sending mail pb 6
Mail Send Problem 4
SMTP-mailserver - how? 6
Emergency 1
MessageBox Question 7
System.Web.Mail - Bad Bug 4
SMTPMAIL 3

Top