473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Mail headers: smtpclient problem

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
2 4016
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joe Reiss | last post by:
Hi all, I'm using the System.Net.Mail namespace to set up a SMTP sendmail. This works for the most part, however, when I try to send email to a cell phone text msg. via the Verizon 'vtext'...
1
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to...
34
by: antonyliu2002 | last post by:
I've set up the virtual smtp server on my IIS 5.1 like so: 1. Assign IP address to "All Unassigned", and listen to port 25. 2. Access Connection granted to "127.0.0.1". 3. Relay only allow...
6
by: rekaeps | last post by:
We are developing an ASP.NET 2.0 (C#) application, and I'm having troubles sending e-mail from the server when accessing the web site from a separate client computer. Also, in the same scenario,...
3
by: dnuos | last post by:
We are developing an ASP.NET 2.0 (C#) application, and I'm having troubles sending e-mail from the server when accessing the web site from a separate client computer. Here's some details: ...
2
by: Alex Maghen | last post by:
I want to use the new System.Net.Mail instead of the old System.Web.Mail. I'm getting an error "Hot not specified" when I try to do my last two lines: System.Net.Mail.SmtpClient SMTP = new...
0
by: howardr101 | last post by:
Hi, Have hunted around on the groups and can't find anything, hence. I've tried this against 2 mail servers (mailtraq and hmailserver) and it occus with both. The problems seems to be that...
2
by: =?Utf-8?B?QWRl?= | last post by:
HI All, I am encountering the following error when I try to send an email through a SMTP server. I believe the problem lies with the authentication part when the network crednetials are used,...
1
by: WIzmanG | last post by:
Hi all I am having trouble with sending email via a C#2.0 application, I use the same settings as I use in Outlook but I cannot get email to send. I am trying to use SSL on port 465 and get the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.