SmtpClient class alternative?

  • Thread starter Thread starter Afshar
  • Start date Start date
A

Afshar

Dear Friends,

I want to send email but don't wanna use SmtpClient class, because I
want more control on generated mail. Is there any good alternative?


Thanks In Advance
 
What kind of control are you talking about. If you want ultimate control, the
SMTP protocal is a fairly simple text based protocal so it wouldnt take long
to write your own.
 
What kind of control are you talking about. If you want ultimate control,the
SMTP protocal is a fairly simple text based protocal so it wouldnt take long
to write your own.

Thanks for reply, but I'm not very familiar with SMTP protocal and
specially its underlying TCP/IP. In fact I didn't leverage any
protocol like this. By "Full Control" I mean: I can select how email
source is generated and I could reduce the size of generated mail.



Afshar
 
Afshar said:
Thanks for reply, but I'm not very familiar with SMTP protocal and
specially its underlying TCP/IP. In fact I didn't leverage any
protocol like this. By "Full Control" I mean: I can select how email
source is generated and I could reduce the size of generated mail.

What's wrong with SmtpClient? You can call the Send() overload that takes a
string as the message body, you have total control over how you generate
that string.
 
Slightly puzzled... What aspect(s) of sending email via theSmtpClientclass
do not provide enough control for you...?

Thanks for attention, I'm developing some prtotocol called ECE over e-
mail. ECE has been invented to relate so many companies/organizations
via their ERP software. Each software developer is supposed to
implement ECE in its software. One of software developers that we had
to communicate with parses just 18 first lines of each email. Since in
the ECE protocol a header named "X-ECE_SEND" must be inserted in the
email and our generated email contains this header after line 18, so
they can not recognize our email as a valid ECE email. And I had to
find some way to insert this header in the first 18 lines of email. I
know the problem may be in MailMessage class but I guess SmtpClient
may be involved too. Here is my code for generating and sending mail
and a typical mail message produced:

------------------------------------------------------------------------------------------------------------------------------------------------------------
Generating mail itself:
public static MailMessage CreateMail(string
attachmentFileName, string letterSubject, List<MailAddress> receivers,
MailAddress sender, string body)
{
System.Net.Mail.MailMessage mail = new
System.Net.Mail.MailMessage();
if (!string.IsNullOrEmpty(attachmentFileName))
{
Attachment attachment = new
Attachment(attachmentFileName);
mail.Attachments.Add(attachment);
}
NameValueCollection headers = new NameValueCollection();
mail.Body = body;
mail.From = sender;
foreach (MailAddress addr in receivers) mail.To.Add(addr);
mail.BodyEncoding = Encoding.UTF8;
mail.DeliveryNotificationOptions =
DeliveryNotificationOptions.OnSuccess;
mail.Headers.Add("X-ECE_SEND", "1.01");
mail.Subject = letterSubject;
return mail;
}


------------------------------------------------------------------------------------------------------------------------------------------------------------
Sending it:

public static void SendMail(MailMessage mail, bool enableSsl)
{
SmtpClient client = new SmtpClient();
client.EnableSsl = enableSsl;
client.Send(mail);
client = null;
}

------------------------------------------------------------------------------------------------------------------------------------------------------------
A typical generated email:

Delivered-To: (e-mail address removed)
Received: by 10.103.12.5 with SMTP id p5cs383851mui;
Sat, 23 Aug 2008 00:28:32 -0700 (PDT)

Received: by 10.210.65.17 with SMTP id n17mr2831948eba.
92.1219476512470;
Sat, 23 Aug 2008 00:28:32 -0700 (PDT)
Return-Path: <[email protected]>

Received: from ey-out-2122.google.com (ey-out-2122.google.com
[74.125.78.26])
by mx.google.com with ESMTP id 7si2421867eyb.
1.2008.08.23.00.28.31;

Sat, 23 Aug 2008 00:28:32 -0700 (PDT)
Received-SPF: pass (google.com: domain of (e-mail address removed)
designates 74.125.78.26 as permitted sender) client-ip=74.125.78.26;

Authentication-Results: mx.google.com; spf=pass (google.com: domain of
(e-mail address removed) designates 74.125.78.26 as permitted sender)
[email protected]; dkim=pass (test mode)
[email protected]

Received: by ey-out-2122.google.com with SMTP id 25so68580eya.49
for <[email protected]>; Sat, 23 Aug 2008 00:28:31 -0700
(PDT)

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=domainkey-signature:received:received:x-ece_send:mime-
version:from
:to:subject:content-type:date:message-id;

bh=3cBPNRMwyp8SEDcCgowEBIREX5AlIk4sOjUZjQdGm1A=;
b=OOY7H1UVJaBX55dEBEzbDUmncmJzdUu66F
+Gl8Mw6ZZhMskvALbwcAIrRuF9psMMka

fI1CpvJcxQcvfrDOaklZPkiqPZ1P0+LqgEncXhZOXrv9GUJVBw9HUSkEXXdYEW1wcbB/

Qub/TL+qp5HsDeU8m+bJsm4pdgLm6AMFWRcws=
DomainKey-Signature: a=rsa-sha1; c=nofws;
d=gmail.com; s=gamma;
h=x-ece_send:mime-version:from:to:subject:content-type:date

:message-id;
b=FM1ToaPqdjn8tk+/OovQX1BM91EYJNmRLu6bz98OdgC/T9NxKBeUrp1C/
jdzQeUDIm
AGgGJ20y18ko7MDrUYCwEyvjIDyl+UHGDkWvG0oI
+grdvGnMD09Tbu8HhQU1onGLx0UR
0EYC0eYsP4wuVzYnmSf0x5drwIG/N0ZGe347g=

Received: by 10.210.125.7 with SMTP id x7mr2792181ebc.
184.1219476510385;
Sat, 23 Aug 2008 00:28:30 -0700 (PDT)
Return-Path: <[email protected]>

Received: from programmer07 ( [91.184.73.21])
by mx.google.com with ESMTPS id p10sm9113630gvf.
7.2008.08.23.00.28.26
(version=TLSv1/SSLv3 cipher=RC4-MD5);

Sat, 23 Aug 2008 00:28:29 -0700 (PDT)
x-ece_send: 1.01
mime-version: 1.0
from: =?utf-8?B?2LTYsdqp2Kog2YHYsdin2qnZhti0?= <[email protected]>
to: =?utf-8?B?
2qnYtNiq24zYsdin2YbbjCDYrNmF2YfZiNix24wg2KfYs9mE2KfZhduMINin24zYsdin2YY=?
=
<[email protected]>

subject: =?utf-8?B?2KrYs9iqINm+2LHZiNiq2qnZhCBFQ0U=?=
content-type: multipart/mixed;
boundary=--boundary_1_471776fe-8fd3-46ee-9de3-30498d59dd48
Date: Sat, 23 Aug 2008 00:28:29 -0700 (PDT)
Message-ID: <[email protected]>



----boundary_1_471776fe-8fd3-46ee-9de3-30498d59dd48
content-type: text/plain; charset=utf-8
content-transfer-encoding: base64

PExldHRlcj48UHJvdG9jb2wgTmFtZT0iRUNFIiBWZXJzaW9uPSIxLjAxIiAvPjxTb2Z0d2Fy

ZSBTb2Z0d2FyZURldmVsb3Blcj0iaHR0cDovL3d3dy5mYXJhY29uZXNoLmNvbS8iIFZlcnNp
b249IjEuMC4wLjAiIEdVSUQ9IkE5MDMyQzhBLUI0R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dd48
content-type: application/octet-stream; name=SendXml_6297.xml
content-transfer-encoding: base64

PExldHRlcj4NCiAgPFByb3RvY29sIE5hbWU9IkVDRSIgVmVyc2lvbj0iMS4wMSIgLz4NCiAg

PFNvZnR3YXJlIFNvZnR3YXJlRGV2ZWxvcGVyPSJodHRwOi8vd3d3LmZhcmFjb25lc2guY29t
LyIgVmVyc2lvbj0iMS4wLjAuMCIgR1VJRD0iQTkwMzJDOEEtQjRFOS00YzA2LThDQTItMDRE
NDQwNTQ3RkFGIiAvPg0KICA8U2VuZGVyIE9yZ2FuaXphdGlvbj0i2LTYsdqp2Kog2YHYsdin

2qnZhti0IiBEZXBhcnRtZW50PSLYqtmI2LPYudmHINiv2YfZhtiv2YciIFBvc2l0aW9uPSLY
qtmI2LPYudmHINiv2YfZhtiv2YciIE5hbWU9Itin2YHYtNin2LEg2YXYrdio24wiIENvZGU9
IjU0NDMiIC8+DQogIDxSZWNlaXZlciBPcmdhbml6YXRpb249Itqp2LTYqtuM2LHYp9mG24wg

2KzZhdmH2YjYsduMINin2LPZhNin2YXbjCDYp9uM2LHYp9mGIiBEZXBhcnRtZW50PSLZvti0
2KrbjNio2KfZhiIgUG9zaXRpb249Itm
+2LTYqtuM2KjYp9mGIiBOYW1lPSLbjNmI2LPZgSDZ
hdix2KfYr9uMIiBDb2RlPSI0NDQ1IiBSZWNlaXZlVHlwZT0iT3JpZ2luIiAvPg0KICA8T3Ro

ZXJSZWNlaXZlcnMgLz4NCiAgPExldHRlck5vPjE4ODA8L0xldHRlck5vPg0KICA8TGV0dGVy
RGF0ZVRpbWUgU2hvd0FzPSJqYWxhbGkiPjIwMDgtMDgtMThUMDA6MDA6MDA8L0xldHRlckRh
dGVUaW1lPg0KICA8UmVsYXRlZExldHRlcnMgLz4NCiAgPFN1YmplY3Q+2KrYs9iqINm
+2LHZ

iNiq2qnZhCBFQ0U8L1N1YmplY3Q
+DQogIDxQcmlvcml0eSBDb2RlPSIwIiBOYW1lPSJOb3Jt
YWwiIC8+DQogIDxDbGFzc2lmaWNhdGlvbiBDb2RlPSIwIiBOYW1lPSJOb3JtYWwiIC8+DQog
IDxLZXl3b3Jkcz4NCiAgICA8S2V5d29yZD7Yqtiz2Ko8L0tleXdvcmQ
+DQogICAgPEtleXdv

cmQ
+2b7YsdmI2KraqdmEPC9LZXl3b3JkPg0KICAgIDxLZXl3b3JkPmVjZTwvS2V5d29yZD4N
CiAgPC9LZXl3b3Jkcz4NCiAgPE9yaWdpbnMgLz4NCiAgPEF0dGFjaG1lbnRzIC8+DQo8L0xl
dHRlcj4=
----boundary_1_471776fe-8fd3-46ee-9de3-30498d59dd48--
 
Afshar said:
Thanks for attention, I'm developing some prtotocol called ECE over e-
mail. ECE has been invented to relate so many companies/organizations
via their ERP software. Each software developer is supposed to
implement ECE in its software. One of software developers that we had
to communicate with parses just 18 first lines of each email. Since in
the ECE protocol a header named "X-ECE_SEND" must be inserted in the
email and our generated email contains this header after line 18, so
they can not recognize our email as a valid ECE email. And I had to
find some way to insert this header in the first 18 lines of email. I

Header order is not guaranteed to be persisted across relays -- in
particular it's common to add various headers as part of moving it
along.
 
And the software developers can't / won't fix their code for you...?


No, they don't want to correct this. They are not supposed to fully
support their code unfortunately.
Thanks of all other friends for their replies.


Afshar
 
Back
Top