Introduction
During the time when I worked on .NET 1.1, I built a library for doing basic mail merge in a Web Service. I started to use the mail client DotNetOpenMail by Mike Bridge which really was doing a good job.
After moving to .NET 2.0, I thought that DotNetOpenMail had become obsolete because Microsoft had introduced their System.Net.Mail library. Generally speaking, this works quite nice, but it has some annoying bugs and RFC violations - which I found out one after another, and which have not come to an end yet. At the same time, the mail merge library grew and became quite comfortable to use.
Background
Sure, with System.Net.Mail, you can send mail messages. The point is: some bugs and RFC violations will increase the spam rating of spam filters for your message, and some mail clients may even show parts as garbage. Besides providing mail merge capabilities, MailMergeLib addresses the following issues:
Bugs fixed in .NET 3.5 SP1:
MailMessage.MailAddressCollection.Clear does not clear the corresponding headers. If you want to re-use an existing MailMessage object for different recipients, you will have to remove the recipients headers yourself (e.g. MailMessage.Headers.Remove("to"))
- Setting the transfer encoding to
TransferEncoding.SevenBit turns into a header text sevenbit, instead of 7bit. sevenbit is not RFC compliant and causes problems with some mail clients.
MailMessage.To.ToString() returns the encoded string only after the message was sent. According to the documentation, this should be the case no matter whether the message was already sent or not.
- Display names of mail addresses that are not all 7bit characters must be encoded. This works fine with every address type except for
to addresses. to addresses will never be encoded, no matter which Encoding parameter is used for a new MailAddress.
Bugs not fixed up to .NET 4.0:
- Quoted-Printable encoding is not limited to a maximum of 76 characters in
System.Net.Mail. RFC 2045 requires that Quoted-Printable encoding encodes lines be no more than 76 characters long. If longer lines are to be encoded with the Quoted-Printable encoding, "soft" line breaks must be used.
- Spaces in display names of a
MailAddress must be encoded.
- With
MailMessage.Headers there is a bug where headers will have white space in an encoded text. This will lead to non-RFC 2047 compliant messages.
- Attachments to a mail message must not have white space in the file name, which is neglected by
System.Net.Mail.
- If the display name of an attachment contains non-ASCII characters
System.Net.Mail throws an exception instead on encoding them. Anyway: The display name of an attachment must be encoded if it contains non-ASCII characters (e.g. Chinese, German Umlaut, etc.)
So although Microsoft has supplied some bug fixes, quite a few can be considered as persistent bugs without too much hope for getting them fixed. So I tried to find ways to fix them on my own. All bugfixes are included in a static class Bugfixer which hopefully won't be needed in one of the glorious future versions of .NET. Pie in the Microsoft sky?
Using the Code
For sending a mail in System.Net.Mail, you'll first create a MailMessage, and then send it with SmtpClient. In MailMergeLib this is quite similar: you'll create a MailMergeMessage and then send it with MailMergeSender.
MailMergeMessage
Create a New Message
One big advantage of MailMergeLib comes from placeholders. {Placeholders} are the field names of a DataTable embedded in any text with curly braces.
So first create the message and adjust some settings. CultureInfo is relevant for formatting placeholders that contain dates, currency or numeric data.
MailMergeMessage mmm = new MailMergeMessage("My subject for {Nickname}");
mmm.CharacterEncoding = Encoding.GetEncoding("iso-8859-1");
mmm.CultureInfo = new System.Globalization.CultureInfo("en-US");
mmm.TextTransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;
mmm.BinaryTransferEncoding = System.Net.Mime.TransferEncoding.Base64;
Formatting Capabilities
It is possible to add standard .NET formatting attributes to your placeholders. For a date that will show the day number and the month's name, you would write: {Date:"{0:dd MMMM}"}.
In case a column of DataRow will have ExtendedProperties for null and/or format, these properties will be used. Examples:
myDataTable.Columns["Date"].ExtendedProperties.Add("format", "{0:F}");
myDataTable.Columns["Date"].ExtendedProperties.Add("null", "#Display for null#");
Of course column types and formatting attributes must fit each other.
Message Body
The message body parts can be added or changed quite easily either by using them as a parameter in the constructor, or by setting the properties:
mmm.HtmlText = new System.IO.StreamReader("HtmlBody.html").ReadToEnd();
mmm.PlainText = new System.IO.StreamReader("TextBody.html").ReadToEnd();
HtmlText and PlainText can contain placeholders. You can insert a text file by using the special syntax {IncludeFile:"file"}. IncludeFile is the column name of the DataTable, while file means to interpret the content as a file name.
Attachments
You may also want to add some personalized attachments by adding placeholders to the file name. E.g.:
mmm.FileAttachments.Add
(new FileAttachment("testmail_{Nickname}.pdf", "sample.pdf", "application/pdf"));
And that's the way to add string attachments:
mmm.StringAttachments.Add(new StringAttachment
("Some programmatically created content", "file.txt", "text/plain"));
Mail Addresses
For sending a mail, we need to supply at least one recipient's address and the sender's address. Again, using placeholders makes it possible to create personalized e-mails.
mmm.MailMergeAddresses.Add
(new MailMergeAddress(MailAddressType.To, "<{Email}>", "{Nickname}"));
mmm.MailMergeAddresses.Add
(new MailMergeAddress(MailAddressType.From, "<from@addr.com>", "From Name"));
Miscellaneous
If your data comes from a DataTable, it may well happen that you have recipients with empty e-mail fields. That's why you may want to set:
mmm.IgnoreEmptyRecipientAddr = true
This will then not throw an exception with empty addresses.
Want to change MailMergeLib's identification? Set...
mmm.Xmailer = "MailMergeLib 2.0";
... to anything you like.
MailMergeSender
In the beginning, MailMergeSender is much like System.Net.Mail.SmtpClient: Create an instance of the class and provide some SMTP related settings.
SMTP Settings
Setup the mail sender:
MailMergeSender mailSender = new MailMergeSender();
mailSender.MessageOutput = MessageOutput.SmtpServer;
Set up SMTP server login details:
mailSender.SmtpHost = "smtp.server.com";
mailSender.SmtpPort = 25;
mailSender.SetSmtpAuthentification("username", "password");
mailSender.LocalHostName = "my.localhostname.com";
EventHandlers
With SmtpClient, you cannot add custom event handlers. MailMergeSender will raise events OnBeforeSend, OnAfterSend, OnSendFailure, OnMergeBegin, OnMergeComplete, and OnMergeProgress:
mailSender.OnAfterSend += new EventHandler<MailSenderAfterSendEventArgs>(
delegate(object obj, MailSenderAfterSendEventArgs args)
{
});
Sending a Message
For the Send job, there are several alternatives:
- Start to send messages as an asynchronous operation, which will not block the calling thread:
mailSender.SendAsync(mmm, myDataTable);
- Start to send messages as a synchronous operation. In this case, you will loop through the rows of your
DataTable, supply the row as variables to the MailMergeMessage and then call Send for each row.
foreach (DataRow dr in myDataTable.Rows)
{
mmm.Variables = dr;
mailSender.Send(mmm);
}
Or just send a single message providing a Dictionary with name/value pairs:
Dictionary<string, string> nameValuePairs = new Dictionary<string, string>();
nameValuePairs.Add("Email", "to@addr.com");
nameValuePairs.Add("Nickname", "Bill");
mmm.SetVariables(nameValuePairs);
mailSender.Send(mmm);
Cancelling a Send Operation
Asynchronous Send operations can be cancelled at any time:
mailSender.SendCancel();
Influencing Error Handling
Timeout in milliseconds:
mailSender.Timeout = 100000;
Maximum number of failures until sending a message will finally fail:
mailSender.MaxFailures = 3;
Retry delay time between failures:
mailSender.RetryDelayTime = 3000;
Delay time between each message:
mailSender.DelayBetweenMessages = 1000;
Conclusion
By fixing the bugs in System.Net.Mail, it was interesting to dig into its design and to supply modifications using System.Reflection. Although all the bugs mentioned were reported to Microsoft a very long time ago, they didn't remove them. Life could be so easy... Anyway, MailMergeLib works well (again, after .NET 3.5 SP1 and .NET 4.0 partly broke it).
Special Thanks To
- .NET Reflector for providing this great tool to analyze
System.Net.Mail and to find out ways to fix its bugs
- Mike Bridge for his
QPEncoder in DotNetOpenMail
- People working on Mono for their
AttachmentBase.MimeTypes
- All users giving their feedback and votes in the forum
History
- 2007-07-10: Initial release
- 2007-07-11: Minor doc and code update
- 2007-10-08: SSL support added (thanks to WPKF),
GetEncodedMailAddress fixed
- 2007-12-28: Re-designed bug fixes in
BugFixer class that .NET 2.0 SP1 / .NET 3.5 broke:
CorrectSubjectEncodedWordRFC2047compliant
AddToAddressWithCorrectEncoding
ClearMessageHeaders
- 2008-01-01: Improvement of the
Tools class
CalcMailSize(MailMessage msg) now gives accurate size instead of an estimation
- Added
GetMailAsMimeString (MailMessage msg) to retrieve the message content (same as in an EML file)
- 2008-01-12: Minor improvements
Tools.WrapLine(string input, int length)will now allow empty lines (thanks to woetertie)
QPEncoder from DotNetOpenMail might return a string 1 byte longer than RFC2027-compliant, fixed
- 2008-05-22: Minor improvement
- Fixed potential problem with zip files
- 2008-08-30: Minor improvements
- Verified: Bugs still exist in .NET 3.5 SP1, and bugfixing of
MailMergeLib works with it
- Updated documentation
- 2009-08-02:
- Verified: Bugs still exist in .NET 4.0, and bugfixing of
MailMergeLib works with it
SmtpClient's private member localHostName (up to .NET 3.5 SP1) changed to clientDomain in .NET 4.0. MailMergeLib can deal with both now.
- Fixed bug in
System.Net.Mail with non-ASCII characters in the display name of an attachment (thanks to xrascal)
- Updated documentation
| You must Sign In to use this message board. |
|
|
 |
|
 |
Based on the RFC , the length of the line should be no more than 78 and that is why in the code the lines are broken to smaller pieces. Now if there is any dot/period in the line that goes to the next line because of this reason, it is ignored by SMTP servers. And the worst part is that if in the line there is only one single dot, it is considered as the end of email and the recipient does not received the rest of email.
The solution can be if there is any . in the very first positoin of the line just replace it with ..(2 dots)
I would appreciate it if any one can give the better solution fot that? Thanks.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I used QuotedPrintable encoding, but when it wraps the line if the very first character is . it causes some problems. The . in the very first column of the line should be replaced with =2E and it solves the problem.
I made this modification in the QPEncoder.cs line 433 (based on the last version)
I modified this line: stringwriter.Write(towrite);
To these lines: if (columnposition == 1 && towrite == ".") { columnposition += 2; stringwriter.Write("=2E"); } else { stringwriter.Write(towrite); }
Is it the right solution?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi! First of all IMHO this is another bug in SmtpClient. Just to make clear to any reader what it is all about: Sending a message with these 2 lines
.. ... will be processed by SmtpClient in a way, that the recipient will get
. .. This is - again - due to a violation of RFC 2821[^] , section 4.5.2 (transparency).
I think the right workaround is what you mentioned in your first post. However, this has nothing to do with encoding quoted-printable the right way. It's the responsibility of SmtpClient to have an RFC compliant transfer of any message to the SMTP server "as is".
For the moment I don't have an idea how to hack SmtpClient in order to solve the "first dot problem".
Norbert
modified on Tuesday, November 10, 2009 2:44 PM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello, my compliments upon an excellent article and upon your well-documented code! And I deeply appreciate your sharing it with us.
I'm trying to use it to send a single email message, very simplistic at this point just to get a message out. I'm using Windows Vista SP1, Visual Studio 2010 beta, and the .NET Framework 4.0 Have you tried it with this framework?
It throws an exception when I call MailSender.Send, saying "Field 'System.Net.Mail.SmtpClient.localHostName' not found."
Tracing it into your code, I see that that happens within the setter localHostName, in MailMergeSender.cs
I'm a bit confused by this portion of your code. You have two setters with almost identical names: LocalHostName, and localHostName. I don't understand the comment on the 2nd: "Gets or sets the name of the local machine sent to the SMTP server a SMTP transaction by using a private member of System.Net.Mail.SmtpClient". But in anycase, I guess you're using reflection here to set this value and perhaps the method signature has changed now?
I appreciate your insight on this - thank you.
jh
James Hurst "The greatness of a nation and its moral progress can be judged by the way its animals are treated."
Mahatma Gandhi
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thanks for the compliments and your vote  In version 4 beta of the .NET Framework the private member "localHostName" of the SmtpClient class was removed by Microsoft . I'll do more investigation on the system.net.mail classes of .NET Fx 4 as soon as I find some time (preferably after it's released). See my post below for a workaround.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thank you Norbert. I noticed that SmtpClient does have a property called "Host" - could that be what Microsoft intends us to use for it? I substituted that, and it seems to work. So, in the context of my limited, barely-minimal test - yes your lib seems to work with .NET 4 thus far.
James Hurst "The greatness of a nation and its moral progress can be judged by the way its animals are treated."
Mahatma Gandhi
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
No, this won't work. "Host" is the SMTP host to be used, while localHostName is the name of the sending machine. See my post below for the slight change to be made in MailMergeSender.cs.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Hi,
I'm trying to send e-mail using the example project from my machine (WIN 7 release). I did some tests on VISTA OS, and WIN 7(BETA), and it's works fine.
I tried to force the _mailSender.LocalHostName, but doesn't work.
Can you help-me?
Thanks.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
MailMergeLib is not (yet) verfied to work with .NET Framework 4.0. In version 4 (at least in the beta I have) the private member "localHostName" of the SmtpClient class seems to be removed by Microsoft, and there's no equivalent. I wonder why, but still... As a fast workaround please remove localHostName = _localHostName; in PrepareSettings() of MailMergeSender.cs
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
|
 |
|
 |
In .NET Framework 4.0 (beta) you have to invoke member "clientDomain" instead of "localHostName". It seems that Microsoft did some refactoring of the code. This is the relevant part of MailMergeSender.cs:
private string localHostName { get { return typeof(SmtpClient).InvokeMember("localHostName", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, _smtp, null).ToString(); } set { string heloName = string.IsNullOrEmpty(value) ? System.Environment.MachineName : value; typeof(SmtpClient).InvokeMember("localHostName", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField, null, _smtp, new object[] { heloName }); } }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Event though I'm not running .NET 4.0 I ran into the same issue. I checked my System.Net version in the GAC, it's 3.5.0.0 with a file version of 3.5.30729.4926. The only thing I can think that's probably different about my setup is I'm running under Windows 7. I change the getter/setter to check for Windows 7/Server 2008 or newer version and that seemed to work:
private string localHostName { get {
if (System.Environment.Version.Major == 4 || (System.Environment.OSVersion.Version.Major > 6) || (System.Environment.OSVersion.Version.Major == 6 && System.Environment.OSVersion.Version.Minor >= 1) ) { return typeof(SmtpClient).InvokeMember("clientDomain", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, _smtp, null).ToString(); }
if (System.Environment.Version.Major == 2 && System.Environment.Version.Build == 50727) { return typeof(SmtpClient).InvokeMember("localHostName", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, _smtp, null).ToString(); }
return System.Environment.MachineName; } set { string heloName = string.IsNullOrEmpty(value) ? System.Environment.MachineName : value;
if (System.Environment.Version.Major == 4 || (System.Environment.OSVersion.Version.Major > 6) || (System.Environment.OSVersion.Version.Major == 6 && System.Environment.OSVersion.Version.Minor >= 1) ) { typeof(SmtpClient).InvokeMember("clientDomain", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField, null, _smtp, new object[] { heloName }); } else if (System.Environment.Version.Major == 2 && System.Environment.Version.Build == 50727) { typeof(SmtpClient).InvokeMember("localHostName", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField, null, _smtp, new object[] { heloName }); } } }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
FYI... I found that my Windows 7 upgrade (from XP) shows an OS version of > 6 (as expected) but the System.Environment.Version.Major still equals 2 (not expected. I expected Net 4.x to be instaslled with Windows 7) and still didn't work. I was running a Net 3.5 project under VS2008. I also commented out the localHost == _localHost and that didn't work either, but with a different error. Due to time contraints, I had to use the regular system.netmail class in the framework and that worked (as expected).
just some thoughts
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
hi Norbert, Why don't you use Base64 Encoding to Encode mail subject direct? Why do you use ShouldUseBase64Encoding to auto- choose the 'B' or 'QP', what it is ?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi, The one and only reason is SPAM ranking of the mail message. If you encode characters unnecessarily, SPAM ranking will get worse. Most popular mail programs act like this. Norbert
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
thank you for your anwser. but i send mail with microsoft outlook express,'Base64' is used for its all mail.what is the reason ?(i am in GB2312 environment.)
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
dear Norbert Bietsch, I am using your mailMergeLib. it is good.thank you very much! But you didn't fixed the bugs of System.Net.Mail completely. I found a bug when i send mail that contain attachment with MailMergeLib.
Let's do a test: // ------------------------------------------------- private TransferEncoding _textTransferEncoding = TransferEncoding.SevenBit; private TransferEncoding _binaryTransferEncoding = TransferEncoding.Base64; private Encoding _characterEncoding = Encoding.GetEncoding("gb2312"); public Attachment GetAttachment() { string filePath = @"d:\中文文件.txt"; //string displayName = "=?gb2312?B?1tDOxM7EvP4udHh0?="; string displayName = "中文文件.txt"; Attachment _attachment = new System.Net.Mail.Attachment(filePath); _attachment.NameEncoding = _characterEncoding;
_attachment.ContentType.MediaType = "text/plain"; _attachment.ContentDisposition.Inline = false; _attachment.ContentDisposition.FileName = "中文文件.txt"; //_attachment.ContentDisposition.FileName = "=?gb2312?B?1tDOxM7EvP4udHh0?="; _attachment.ContentDisposition.CreationDate = System.IO.File.GetCreationTime(filePath); _attachment.ContentDisposition.ModificationDate = System.IO.File.GetLastWriteTime(filePath); _attachment.ContentDisposition.ReadDate = System.IO.File.GetLastAccessTime(filePath); displayName = displayName.Replace(" ", string.Empty); if (_attachment.ContentType.MediaType.ToLower().StartsWith("text/")) { _attachment.ContentType.CharSet = _characterEncoding.HeaderName; _attachment.TransferEncoding = _textTransferEncoding; } else { _attachment.ContentType.CharSet = null; _attachment.TransferEncoding = _binaryTransferEncoding; } return _attachment; }
// ------------------------------------------------- The code will throw a FormatException:'MailHeaderFieldInvalidCharacter' .('在邮件标头中找到无效的字符。') because the "_attachment.ContentDisposition.FileName" is set by Chinese character.
if use the code : _attachment.ContentDisposition.FileName = "=?gb2312?B?1tDOxM7EvP4udHh0?="; that will work. so , i think that is a bug.the _attachment.ContentDisposition.FileName should be encoded with Base64 or QP. if it doesn't encoded , the code don't work when use the Chinese character , Korea character etc.
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
i have fixed the bug of Attachment.ContentDisposition.FileName .
in the BugFixer.cs,I add a method to encode the Attachment.Name:
public static void EncodeAttachmentFileName(ref String displayName, Encoding enc) { if (System.Environment.Version.Major != 2 || System.Environment.Version.MajorRevision != 0 || System.Environment.Version.Build != 50727) return;
object mimePart = typeof(System.Net.Mail.AttachmentBase).InvokeMember("part", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, new Attachment(new System.IO.MemoryStream(new ASCIIEncoding().GetBytes(string.Empty)), "dummy"), null);
string _displayName = displayName;
bool IsAscii = Convert.ToBoolean(mimePart.GetType().BaseType.InvokeMember("IsAscii", BindingFlags.DeclaredOnly | BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.InvokeMethod, null, mimePart, new object[] { _displayName, false }));
if (((_displayName != null) && (_displayName.Length != 0)) && !IsAscii) { if (enc == null) { enc = Encoding.GetEncoding("utf-8"); }
bool ShouldUseBase64Encoding = Convert.ToBoolean(mimePart.GetType().BaseType.InvokeMember("ShouldUseBase64Encoding", BindingFlags.DeclaredOnly | BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.InvokeMethod, null, mimePart, new object[] { enc }));
_displayName = mimePart.GetType().BaseType.InvokeMember("EncodeHeaderValue", BindingFlags.DeclaredOnly | BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.InvokeMethod, null, mimePart, new object[] { _displayName, enc, ShouldUseBase64Encoding }).ToString();
if (!ShouldUseBase64Encoding) displayName = _displayName.Replace(" ", "=20"); } }
// ---------------------------------------------------- in the AttachmentBuilder.cs, i update the construct:
public AttachmentBuilder(FileAttachment fileAtt) { _attachment = new Attachment(fileAtt.Filename); _attachment.ContentType.MediaType = fileAtt.MimeType; _attachment.ContentDisposition.Inline = false; string _DisplayName = fileAtt.DisplayName; //use bugfixer to encode the _DisplayName. Bugfixer.EncodeAttachmentFileName(ref _DisplayName, _characterEncoding); _attachment.ContentDisposition.FileName = _DisplayName; _attachment.ContentDisposition.CreationDate = System.IO.File.GetCreationTime(fileAtt.Filename); _attachment.ContentDisposition.ModificationDate = System.IO.File.GetLastWriteTime(fileAtt.Filename); _attachment.ContentDisposition.ReadDate = System.IO.File.GetLastAccessTime(fileAtt.Filename); _attachment.NameEncoding = _characterEncoding; _attachment.Name = _DisplayName;
if (_attachment.ContentType.MediaType.ToLower().StartsWith("text/")) { _attachment.ContentType.CharSet = _characterEncoding.HeaderName; _attachment.TransferEncoding = _textTransferEncoding; } else { _attachment.ContentType.CharSet = null; _attachment.TransferEncoding = _binaryTransferEncoding; }
//Bugfixer.CorrectSevenBitTransferEncoding(_attachment); Bugfixer.CorrectQuotedPrintableRFC2045compliant(_attachment, _characterEncoding); }
// ---------------------------------------------------------- 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Welcome to the crew of unknown MS freelancers and thanks for your contribution. I'll add it to the next release which will also cover .NET 4.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Norbert Sorry, I'm not powerful with English, I try to explain my problem as I can
I have a problem with specified SMTP server - smtp.sasktelmail.com. It's our corporate email provider. I used CDOSYS library with .NET 1.1 web application to send emails using this SMTP
Now I implementing new version of that application under .NET 3.5 I desided to not use old CDOSYS lib, and tried to migrate to System.Net.Mail
But my SMTP provider refusing to send emails using it. I tried to use different SMTP providers, and everything OK with them. So problem is not in settings, problem with SMTP server itself
I run into the problem deeply, and found that some users also experienced problems with this SMTP provider.
Let's assume changing SMTP provider is not a choice. Using CDOSYS library is 'escape way' in case if I not find solution. We are in negotiations with SMTP provider, but I'm not sure they will change something on their side
Here go technical details about the issue
Error itself: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 No AUTH command has been given.
Here's the link with user with same problems on same SMTP server
Now teltet information (bold text 0 is user input. Not bold text - returned from stmp provider)
======SUCCSES TO CONNECT TO SMTP SERVER ===== ehlo localhost 250-bgmpomr2.sasknet.sk.ca 250-8BITMIME 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-HELP 250-XLOOP 3A35E0CA11D432DC00089F0FC11C0059 250-STARTTLS 250-AUTH PLAIN LOGIN 250-AUTH=LOGIN 250-ETRN 250 SIZE 0 auth login 334 VXNlcm5hbWU6 p3ltcAKw89== 334 UGFzc3dvcmQ6 ZcM67Bhyl4== 235 2.7.0 login authentication successful.
======THIS WAY MICROSOFT SYSTEM.NET.MAIL SENDS ===== ehlo localhost 250-bgmpomr2.sasknet.sk.ca 250-8BITMIME 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-HELP 250-XLOOP 3A35E0CA11D432DC00089F0FC11C0059 250-STARTTLS 250-AUTH PLAIN LOGIN 250-AUTH=LOGIN 250-ETRN 250 SIZE 0 auth login p3ltcAKw89== 501 5.5.0 Invalid input (Invalid authentication protocol)
As you can see - Microsoft System.Net.Mail sends user login in 1 line with "auth login" command. In most SMTP servers it works. But not with this specified SMTP question
So here is a question:
Is it possible to change to force sending "auth login" and user login as separate commands? Some kind of 'hack' of something Or better to return to CSOSYS ^^
I will glad for any reply. Thanks
modified on Wednesday, March 4, 2009 6:13 AM
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
|
 |
|
 |
I have used MailMergeLib to create an email web service and it's been working fine. Sometimes (In the past 6 months it has happened 2 times) the email is sent to the all recipients tons of times. I really don't know if it is MailMergeLib problem or what. In my ASP.NET code I call that web service to send email to the recipients. Yesterday only one of our customers got 1200 emails, all the same. I reviewed all the code and could not find anythning wrong. Could somebody please help me. Thanks.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi, unless you pass more information about which way you have implemented MailMergeLib it's hard to give any advice. I'm running such a web service for about 2 years without any problem. So I would start to review the way your web service uses MailMergeLib, and then how your ASP.NET app uses the web service.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thanks for the reply. Yesterday it happened again and I noticed the following information: In windows event log at that time for calling the emailing web service the following error happened:
The operation has timed out.
Stack trace: at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request) at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request) at Microsoft.Web.Services3.WebServicesClientProtocol.GetResponse(WebRequest request, IAsyncResult result) at Microsoft.Web.Services3.WebServicesClientProtocol.GetWebResponse(WebRequest request)
Strange thing is that in IIS log file there is no entry at that time to that specific asmx file. And also our provider said that at that time SMTP server had an oputage.
When everything is fine in netwotk and SMTP server, it works without any problem. I really need help on this matter, Thank you.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|