System.Net.Mail.SmtpClient - not sending emails with attachments sized less than 200kb

R

Robson Siqueira

Folks,

I've been experiencing a weird problem. I have a web service which sends an
email after its processing. The email always has an PDF attachment on it.
The PDF size vary overtime.

The problem is that everytime the PDF size is equal to or less than 200 KB,
the email is just not being sent. There are no error messages, nothing.

Here is a piece of code.

[WebMethod]

public string TestSendEmail(string email)

{

string[] files = Directory.GetFiles(@"c:\temp", "*.pdf");

for(int i = 0; i < files.Length; i++)

{

MailMessage msg = new MailMessage(new
MailAddress("(e-mail address removed)"), new MailAddress(email));

msg.Subject = "test";

msg.Body = "test";

try

{

Attachment at = new Attachment(files);

msg.Attachments.Add(at);

}

catch (Exception ex)

{

EventLog.WriteEntry("test", ex.ToString(),
EventLogEntryType.Error);

}

SmtpClient c = new SmtpClient("mysmtpserverIP");

c.Send(msg);

}

return "success";

}


What happens is that all attachments which size is bigger than 200KB are
sent normally. The other files, don't

Any thoughts?
 
R

Robson Siqueira

Folks,

Problem was found. If you don't specify the MIME type for attachments which
size is less than 200 KB (at least in our case, using .Net 2.0 and a
Microsoft SMTP server), the server just ignores the email.

So we changed the code to

Attachment at = new Attachment(files,
System.Net.Mime.MediaTypeNames.Application.Pdf);

Now works perfectly.

If you guys find articles or any information about it, please let me know.
 

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

Top