By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,490 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,490 IT Pros & Developers. It's quick & easy.

Mail headers: smtpclient problem

P: n/a
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

Jul 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
"fhtino" <fh****@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
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

Jul 27 '06 #2

P: n/a
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
Kevin Spencer wrote:
Why don't you just remove the headers it has by default, and add your own?
Jul 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.