Mail headers: smtpclient problem

  • Thread starter Thread starter fhtino
  • Start date Start date
F

fhtino

Hello,

I'm trying to create an email message with particular headers. A piece
of code:

SmtpClient smtp = new SmtpClient("192.168.x.y");
MailMessage msg = new MailMessage("from@xxxxxxx", "to@xxxxxx", "TEST",
"");
msg.Headers.Add("Content-Type", "application/pkcs7-mime;
smime-type=signed-data; name=\"smime.p7m\"");
msg.Headers.Add("Content-Disposition", "attachment;
filename=\"smime.p7m\"");
msg.Headers.Add("Content-Transfer-Encoding", "base64");
msg.Body = Convert.ToBase64String(encodedData);
smtp.Send(msg);


SmtpClient seems to not consider my headers and adds its headers.

The received message contains some headers twice:

content-type: application/pkcs7-mime; smime-type=signed-data;
name="smime.p7m"
content-disposition: attachment; filename="smime.p7m"
content-transfer-encoding: base64
mime-version: 1.0
from: xxxxxxxxxxxxxx
to: xxxxxxxxxxxxxxxx
date: 27 Jul 2006 11:02:43 +0200
subject: TEST
content-type: text/plain; charset=us-ascii
content-transfer-encoding: quoted-printable


There are 2 content-type and 2 content-transfer-encoding.


Is there a way to force SmtpClient to not add its own headers?
Or, if it's not possible, is there another way to achieve the same
result?


Thank you very much


Best regards

Fabrizio
 
Why don't you just remove the headers it has by default, and add your own?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Magician

A man, a plan, a canal.
a palindrome that has gone to s**t.
 
Because there are only my headers.
SmtpClient adds new headers (I suppose).


Before calling smtp.Send(msg):

msg.Headers.AllKeys
[0]: "content-type"
[1]: "content-disposition"
[2]: "content-transfer-encoding"


After calling smtp.Send(msg):

msg.Headers.AllKeys
[0]: "content-type"
[1]: "content-disposition"
[2]: "content-transfer-encoding"
[3]: "mime-version"
[4]: "from"
[5]: "to"
[6]: "date"
[7]: "subject"


But the resulting message contains more headers:

content-type: application/pkcs7-mime;
smime-type=signed-data;name="smime.p7m"
content-disposition: attachment; filename="smime.p7m"
content-transfer-encoding: base64
mime-version: 1.0
from: xxxxxxxxxxxxxx
to: xxxxxxxxxxxxxxxx
date: 27 Jul 2006 11:02:43 +0200
subject: TEST
content-type: text/plain; charset=us-ascii
content-transfer-encoding: quoted-printable


Fabrizio
 
Back
Top