non useful log about wrong e-mail address format

This is the place to report bugs and get support. When posting in this forum, please always provide as much detail as possible.

Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum, do not report it as a bug.

This is the place to report bugs and get support

When posting in this forum, please try to provide as many relevant details as possible. Particularly the following:

  • What operating system were you running when the bug appeared?
  • What database platform is your site using?
  • What version of mojoPortal are you running?
  • What version of .NET do you use?
  • What steps are necessary to reproduce the issue? Compare expected results vs actual results.
Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum.
This thread is closed to new posts. You must sign in to post in the forums.
11/24/2009 5:08:40 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

non useful log about wrong e-mail address format

When user posts comment at my contact us page I get the following log (I can see the post ok at the site's "see messages" frame when logged in as admin, but never receive them by e-mail)

 

The error message isn't useful, since it doesn't tell me which exact string has the problem (it has to do with SMTP settings in my user.config obviously)

 

--- 

<add key="DisableDotNetOpenMail" value="false" /> <!-- also tried with this set to true -->

<add key="SMTPServer" value="..." />

<add key="SMTPRequiresAuthentication" value="true" />

<add key="SMTPUseSsl" value="false" />

<add key="SMTPPort" value="25" />

<add key="SMTPUser" value="..." /> <!-- tried both user and user@server here -->

<add key="SMTPPassword" value="..." />

<add key="SMTPTimeoutInMilliseconds" value="30000" />

<!-- leave this blank for ascii encoding -->

<add key="SmtpPreferredEncoding" value="utf-8" />

 

*** could it be the "utf-8" smtp encoding setting the problem there? (user.config file is saved in utf-8 format, checked just in case)

---------

2009-11-25 00:34:01,989 ERROR mojoPortal.Web.ContactUI.ContactForm - System.FormatException: The specified string is not in the form required for an e-mail address.

at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset, String& displayName)

at System.Net.Mail.MailAddress.ParseValue(String address)

at System.Net.Mail.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding)

at System.Net.Mail.MailAddress..ctor(String address)

at mojoPortal.Net.Email.SendEmailNormal(SmtpSettings smtpSettings, String from, String replyTo, String to, String cc, String bcc, String subject, String messageBody, Boolean html, String priority, String[] attachmentPaths, String[] attachmentNames)

at mojoPortal.Net.Email.SendEmailNormal(SmtpSettings smtpSettings, String from, String replyTo, String to, String cc, String bcc, String subject, String messageBody, Boolean html, String priority)

at mojoPortal.Net.Email.SendEmail(SmtpSettings smtpSettings, String from, String replyTo, String to, String cc, String bcc, String subject, String messageBody, Boolean html, String priority)

at mojoPortal.Web.ContactUI.ContactForm.btnSend_Click(Object sender, EventArgs e)

2009-11-25 00:35:17,902 INFO mojoPortal.Web.Global - Global.asax.cs Application_End

2009-11-25 00:35:29,225 INFO mojoPortal.Web.Global - Application Started.

 



11/28/2009 5:45:55 AM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

Can anyone help with this one? I've tried everything (even enabling per site settings so that my form uses settings specified by the site admin and not in web.config)

In user.config I now have the following:

<add key="EnableSiteSettingsSmtpSettings" value="true" />

<add key="MaskSmtpPasswordInSiteSettings" value="true" />

<add key="ShowSmtpEncodingOption" value="true" />

<add key="DisableDotNetOpenMail" value="false" />

but keeps on saying the same message in the log (the strange thing is that the exception trace seems to be the same irrespective of the DisableDotNetOpenMail setting - is that option working at all?).

...

at mojoPortal.Net.Email.SendEmailNormal(SmtpSettings smtpSettings, String from, String replyTo, String to, String cc, String bcc, String subject, String messageBody, Boolean html, String priority)

at mojoPortal.Net.Email.SendEmail(SmtpSettings smtpSettings, String from, String replyTo, String to, String cc, String bcc, String subject, String messageBody, Boolean html, String priority)

...

11/28/2009 6:16:54 AM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

Hi George,

The problem is that as soon as you set this to true:

<add key="EnableSiteSettingsSmtpSettings" value="true" />

it now ignores the smtp settings from config file and looks for them as site settings which you have not populated.

When you set that to true, a new tab appears in the site settings page for entering the smtp settings.

I also recommend you set DisableDotNetOpenMail back to true and just let it use the System.Net.Mail classes. I may get rid of DotNetOpenMail, it initially offered some promise of features not included in the framework (like multi part messages with both an html and plain text body) but over time it has shown that it has issues of its own. Currently there is no benefit to using it.

Also if RunningInMediumTrust = true in Web.config it will not use DotNetOpenMail either.

Hope it helps,

Joe

11/28/2009 10:46:23 AM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

Thanks for the reply Joe,

but it's not that the problem, I have filled-in the details at the site settings tab ok (I did it on purpose to make the settings easier to maintain and in the process of trying to troubleshoot why I can't send any e-mail from the portal [I never made it to])

we're not in medium trust and have tried with both values of DisableDotNetOpenMail (I'll set it to true again)

I wonder which is the offending e-mail string. Isn't the exception saying which one it is? (else couldn't you add some direct calls to that parsing function that .NET calls at the phase where you load site options the 1st time and also when those settings are updated from the GUI [both for the config files and the site settings tab that is]). That way we'd know what the offending string is exactly (you'd catch that exception and spit it out together with the exception)

11/28/2009 10:50:04 AM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

Have you populated the default email from address in site settings? It should usually use the same email address as the smtp account.

Have you populated the address to send the contact form submission to in the settings of the contact form with a valid email address?

11/28/2009 10:51:11 AM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

Btw, another reason I set it to use per-site settings was so that the contact form wouldn't use the web.config ASP.net mail settings (in case they were the probkem) but the ones I set at the GUI (according to your docs) - in both cases though I see the exact same error trace and same error. Is it correct that the contact form will use the per site settings?

11/28/2009 10:51:40 AM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

I don't think you can use utf8 encoding for email. Change that to an empty string.

11/28/2009 10:55:51 AM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

also using the following at web.config, but it didn't help that I added deliveryMethod="Network" and defaultCredentials="false" (if defaultCredentials is true at machine.config it will ignore userName/password). Trying using a userName with and without @mymailserver... too with no luck

------------------- 

<system.net>

<mailSettings>

<smtp deliveryMethod="Network" from="...@...">

<network defaultCredentials="false" host="..." port="25" password="..." userName="..." />

</smtp>

</mailSettings>

</system.net>

11/28/2009 11:03:01 AM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

my issue is with:

System.FormatException: The specified string is not in the form required for an e-mail address.

at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset, String& displayName)

at System.Net.Mail.MailAddress.ParseValue(String address)

at System.Net.Mail.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding)

at System.Net.Mail.MailAddress..ctor(String address)

at mojoPortal.Net.Email.SendEmailNormal(SmtpSettings smtpSettings, String from, String replyTo, String to, String cc, String bcc, String subject, String messageBody, Boolean html, String priority, String[] attachmentPaths, String[] attachmentNames)

...

mojoPortal.Net.Email.SendEmailNormal should wrap calls to System.Net.Mail.MailAddress constructor and throw a better exception message letting me know if it's the From, the replyTo, the To, the cc or bcc string that's the issue and what's exactly the offending value (of course the offending value html encoded or something to avoid code injection attacks by people perusing the contact form to attack the admin when they use the log viewer)

11/28/2009 11:04:03 AM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

Yes, the contact form will use the settings from site settings.

Are you sure about the to and from address being correct? You did not answer.

I just found this so maybe I need to add code to make it use utf-8 if specified. But the error is about the email address not the body encoding.

11/28/2009 11:08:41 AM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

I will add a catch for format exception to show the addresses in the error.

11/28/2009 11:12:34 AM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

also tried with utf-8, latin1, iso-8859-1 for the encoding setting

11/28/2009 11:14:56 AM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

As I said the error message is about the address. There are only a to and a from please verify they are both valid email addresses.

11/28/2009 11:19:11 AM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

I have the site e-mail address (at 1st page) set ok (that's the from I guess). The SMTP user is set too (tried it both as user and user@server). Also of course the form filled (by me) has the person's email address set. Is there other e-mail too to set somewhere?

11/28/2009 11:22:38 AM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

I already asked you:

Have you populated the default email from address in site settings? It should usually use the same email address as the smtp account.

Have you populated the address to send the contact form submission to in the settings of the contact form with a valid email address?

So it sounds like you did not set the one in the contact form settings. Click the settings link next to the title of the form. This is who to send the form to.

11/28/2009 11:27:14 AM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

If that does not solve it let me know and I will create a build for you with better logging.

Best,

Joe

11/28/2009 11:30:31 AM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

tried with empty encoding too, no luck

btw, I don't think you need to add special support for utf-8 if you use .NET classes to send e-mail (the doc link you posted says .NET will use BASE64 or whatever encoding needed if you say the mail is in Unicode [UTF-16] or UTF-8 or UTF-32).

Just make sure you don't parse manually that encoding string, but use .NET's classes to get an Encoding instance out of an encoding name (let me know if you can't spot the way to do that, had done it at LvS project [http://www.codeplex.com/LvS] but don't remember at the moment if it was totally straightforward like using a constructor or there was some factory method elsewhere)

As for mail headers, they use their own encoding scheme that contains the encoding at the start of say the from, to etc. fields in something like ?encoding? (if I remember well) with the encoded data following - .NET should be taking care for it (checkout PHP's mb_encoding_mime_header for examples [e.g. see discussions at end of page])

11/28/2009 11:31:37 AM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

The reason it always does not use DotNetOpenMail for the contact form is that we are passing the user's email address as a ReplyTo address and replyto is not supported by DotNetOpenMail.

11/28/2009 11:35:35 AM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

Aha!

Was using "myself@somewhere.com;someother@somewhereelse.com" there and it was choking on it (should it? does it expect "," there to send to many people or doesn't it support sending to many people at all? - I think you should make a splitter that works with both "," and ";" and makes an array of mail addresses to feed to .NET if it doesn't support it directly)

Thanks for looking into the better logging too, would have helped if I could see that string since I'd go and search for where else it may have been defined in the GUI (had set it when I first set up the contact form and didn't remember about it being there to guess that was the issue)

11/28/2009 11:37:18 AM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

The reason I said I need to add it is that the current code is not specifying it at all. Previously we were using encoding only for DotNetOpenMail but it is a different kind of thing like you would use koi8-r for Russian whereas the .NET ones use either ascii utf8 utf32 or unicode. But currently it is not specified at all so it is always using ascii at the moment.

If you verified that you have valid email addresses both in the to and from and you think the body and subject encoding has any effect on it I can make a build that will use utf-8 utf-32 or unicode and you can see if that solves it but, I do not think it is an encoding issue.

Best,

Joe

11/28/2009 11:38:10 AM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

support for non-latin e-mail bodies is too needed if it doesn't exist already

also from what I understand you can define the mail template at email.config or something? Why not define/edit visually a template (and maybe have dropdown to choose from some ready made ones and add yours there too [with option to be portal global maybe if user is admin]) at the contact form settings and/or at site e-mail settings?

11/28/2009 11:45:24 AM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

I will add a splitter support but I think we should pick either , or ; not both and I will add info about the splitter in the help link. Though I guess if I pick comma I can just replace semi colon with comma before splitting.

I was also thinking about making an option where the user could pick from a list and it could go to different addresses. Like maybe if the splitter is | we make a choice dropdown and also include an alias with a | splitter so we don't show the real address in the dropdown so the same form could have a choice for Tech Support, Sales etc.

So maybe we have email address like:

techsupport1@myssite.com,techsupport2@mysite.com|sales@myssite.com

and an alias like

Support|Sales

and from that we can show a dropdown choice to the user with Sales or Support, then further split by comma to send to the different addresses.

Best,

Joe

11/28/2009 11:49:41 AM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

also from what I understand you can define the mail template at email.config or something? Why not define/edit visually a template (and maybe have dropdown to choose from some ready made ones and add yours there too [with option to be portal global maybe if user is admin]) at the contact form settings and/or at site e-mail settings?

There are a million possible improvements to any given feature, everything progresses incrementally and according to my own priorities to advance the project and make a living.

Best,

Joe

11/28/2009 12:12:07 PM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

I just added support for the .NET allowed encodings in my copy so this will be in the next version.

The history is that mojoPortal began it's life under .NET 1.1 which did not support anything but ascii, I found DotNetOpenMail and it was used by default and was a better option for a long time in mojoPortal but no-one was maintaining that project so it began to show problems and limitations over time. Apparently the support for utf8 and others was added in .NET 2.0 but I did not notice it because DotNetOpenMail was still working well at that point and there was no reason to change. I have not had complaints about encoding problems and only realized that .NET mail classes support these encodings today after researching to help you.

Going forward I will remove DotNetOpenMail since it now has various problems and limitations and the .NET mail classes are better at this point.

Best,

Joe

11/28/2009 12:49:13 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

regarding the splitter, I think Unix style is ; and MS style used to be , in the past (in older Outlook Express if I remember well)

now Outlook 2007 supports both (changes , to ; as you write more addresses at say the To field)

11/28/2009 12:55:13 PM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

I will make it support both by just replace ; with , before splitting.

Best,

Joe

11/28/2009 12:58:49 PM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

If I produce a build with the utf-8 support would you be willing to test it for me using some Greek chars in the email? I'd like to make sure it is going to work before I completely remove DotNetOpenMail. I will also include the splitting in the build so you can set it back to multiple addresses like you had before.

Actually it won't really require a full installation I could just send you an updated mojoPortal.NET.dll after I complete the changes.

Best,

Joe

11/28/2009 12:59:25 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

regarding the aliases, it could use the standard style of

 username <email>

and also the syntax

 username [email]

that Unix used to support (think I remember this well) and which Outlook converts to <...> (try writing geo [test@test.com] and pressing TAB at To field in a new mail at outlook 2007)

in fact that syntax should be available everywhere in mojoPortal where you define an e-mail address (using < and > in the XML is problematic - e.g. the syntax highlighter of Visual Web Designer chokes when writing "george <geo@test.com>" and parses it wrong and not sure if &lt; and &gt; are usable inside the XML string - outside of it would be clumsy to write since you'd have to concat multiple strings there). But you could allow "person [email]" in all strings and convert [ and ] to < and > before you pass it to MailAddress factory/constructor (check first in case it already supports the [...] and from which version and up - the <..> it should support for sure I believe, so you could use the "name" from the "name <mail>" for dropdowns if user gave one and if the name is empty show the mail [maybe MailAddress parses/splits it for you and gives you the parts already, checkout its properties/methods])

11/28/2009 1:11:08 PM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

I'm not talking about aliases for the email message itself what I meant was to not reveal the email address in the dropdown list that the user picks we would alias it in the dropdown with a simple string like Support or Sales. When it send the message it will just use the email address. If no alias is provided it will just list the email address in the dropdown. The alias in the dropdown could still refer to more than one email address, so the Support alias could still send to multiple support addresses separated by commas if needed.

11/28/2009 1:19:08 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

but anyway, does it currently support the 

name <mail> 

and 

name [mail]

formats for addresses or just the plain e-mail?

(feel free to send me dll to try)

11/28/2009 1:27:04 PM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

I'll send the dll shortly, backup your original just in case. The new dll will support utf-8, utf-32, or unicode encoding and will handle splitting the to addess on either comma or semi colon and it has better log messages. If an unknown encoding is used it will use utf-8. It also supports splitting for cc and bcc but these are not used by the contact form. Those are the only changes at this time.

No it does not currently support anything but email address.

Thanks,

Joe

11/28/2009 1:45:43 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

.NET and SMTP should support any encoding, as long as you use base64 for the TransferEncoding (for single-byte ones you could also use QuotedPrintable [instead of 7-bit which will eat up data for sure], but using base64 is best since it also support multibyte ones like UTF-16 [the classic Unicode encoding]).

 

At LvS, at LvS_Utilities\subtitles\BaseSubtitleWriter.vb, I'm using:

 

Using writer As New StreamWriter(path, False, theEncoding)

  WriteSubtitles(subtitles, writer)

End Using

 

so you could use StreamWriter to write to any encoding the user told you to use, then tell .NET to use base64 for the TransferEncoding so that SMTP can transfer it fine

My experience on the above is from lots of research I had to do recently to fix osCommerce (well known PHP store) to send e-mails with Greek text. BTW, in osCommerce they have a store name that is used as the display name for e-mails (decent e-mail clients show both the display name AND the e-mail address, so there's no issue with phising - anyway SMTP headers can be faked to say anything - my comment regarding spam filters was that I think they have higher chance to catch a post that just has a newly seen from e-mail address with no display name, but I might be wrong with that [could check SpamAssassin's rulebase for example, although other engines use PETRI nets, neural nets etc. that are not always easy to checkout])

11/28/2009 1:56:33 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

btw, regarding encoding display names, the following:

    =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=

means ISO-8859-2 base64 encoding 

 

and

    =?ISO-8859-1?Q?Patrik_F=E4ltstr=F6m?= <paf*nada.kth.se> 

means ISO-8859-1 quoted-printable encoding (I replaced @ with * to cater for spam-bots)

 

Take a look at IETF's RFC 1522 (but maybe easier is to look at the PHP link I had sent to, has useful discussion at the bottom of that page, and if I remember well code samples that you could adapt too)



11/28/2009 2:06:53 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

Also, regarding message body, .NET supports any encoding from what I understand, according to what is written at reference of BodyEncoding class on MSDN, not just us-ascii and "Unicode" (in the general sense) ones, like UTF-8, UTF-16 (this is called Unicode encoding officially in .NET if I'm not mistaken) and UTF-32. It's just that for the last 3 ones .NET selects a TransferEncoding of Base64 (instead of 7-bit or QuotedPrintable) for the MailMessage. 

From your replies above I understood you were saying .NET doesn't support say Russian encoding (or ISO-8859-7 [Greek]) etc. which doesn't sound accurate (in fact some older mail clients don't support UTF-8 so many admins would opt for using ISO-8859-7 in Greece)

11/28/2009 2:08:52 PM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

Adding display name is not a high priority concern for me at this time, not one person has ever requested it before. I may look into it at some point but there are many more useful and interesting things to work on.

Best,

Joe

11/28/2009 2:12:45 PM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

I will look into additional body encodings, if you find a comprehensive list of ones used in email and supported in .NET let me know as that would be helpful. I figured that generally everyone could use the unicode ones. Seems like modern email clients should handle this.

11/28/2009 2:14:15 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

I think if one has a store they expect to be able to send e-mails displaying the store name, not the e-mail address, plus also spam filters I think will catch such e-mails at highest probability if they have a plain e-mail address (I might be wrong on that, but that's my feeling)

11/28/2009 2:20:05 PM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

When I get confirmation from amazon.com it comes just from auto-confirm@amazon.com and when I get email from PayPal it comes from service@paypal.com. In some ways I think display name is dangerous for commerce because it is shown instead of the email in some clients and may be easier to do phishing with that approach.

I see display name as a nice to have but not high priority.

Best,

Joe

11/28/2009 2:48:15 PM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

I found this list of text encodings on msdn, note that there is an * on the right column if it is supported in .NET and it says iso-8859-7 (Greek) is not supported. So it seems what is supported by .NET on the server would be more of a concern than what is supported on some old legacy email clients that some very small percent of users may use and the unicode family of encodings would be the preferred way to go.

Best,

Joe

11/28/2009 2:56:18 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

The * is what is supported irrespective of codepages installed on the server. Such codepages are installed from Regional Settings (or if you have localized OS are preinstalled). You'd expect that an admin who wants to send ISO-8859-7 Greek text will have that codepage on their server, or ask their host (say if they use shared hosting) to add it (easy and no real overhead to do [just tiny disk space fraction to install the .NLS file]).

11/28/2009 3:02:48 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

Somehow it lost another post I just did where I was saying that StreamWriter constructor has Encoding parameter. You can tell it to use any encoding (as long as appropriate codepages are installed on the system if the encoding isn't supported out of the box by .NET)

So you encode the text (from Unicode that mojoPortal uses internally I assume) to any encoding the user asked for and then you tell .NET to use TransferEncoding of base64 (to format the data for SMTP transfer since SMTP supports 7-bit, 1000 chars per line internally or something). Could use QuotedPrintable for single byte ones like ISO-8859-7 (not 7-bit that would probably zero the 8th bit), but base64 covers multibyte ones too like classic Unicode (UTF-16) or UTF-32 so it's better to use that for any non us-ascii encoding (including Greek, Russian etc.)

11/28/2009 3:04:56 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

btw, regarding display names and stores, my experience with OSCommerce is that it supports the store name in the from field and decent e-mail clients should show both the (decoded) display name and the e-mail address in the format that .NET DisplayName property (see its ref) also shows, that is name <mail> if name is defined, else shows just mail (but not <mail>)

regarding phising, SMTP headers can be faked, it's totally unsafe anyway to trust

11/28/2009 3:05:12 PM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

Ok, I missed that part. I will see about adding support for all of them then using the GetEncoding method and if it returns an argument exception I will log it and fall back to utf-8.

Best,

Joe

11/28/2009 3:08:05 PM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

you tell .NET to use TransferEncoding of base64

How do you do that? I did not see anything on the MailMessage or smtpclient classes to specify it?

btw, it is saturday evening I'm probably done with the forums for today.

Best,

Joe

11/28/2009 3:23:23 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

Strange, it says "If you set the BodyEncoding property to UTF8, Unicode, or UTF32, the Framework selects a TransferEncoding of Base64 for this MailMessage.", but only AttachmentBase has way to set TransferEncoding (btw, there's also a SubjectEncoding property for MailMessage you have to take in mind).

I guess they have some internal property to set the TransferEncoding for the MailMessage (maybe a protected one that you could surface using a descendent class [if allows inheritance]), else the doc is wrong or misleading there.

I think I know what they do though, they use MIME/Multipart and make an empty main message and add an alternate view as attachment to the AlternateViews collection (the attachment allows you to use TransferEncoding). AlternateViews should also be used with HTML mails I guess.

Use the AlternateViews property to specify copies of an e-mail message in different formats. For example, if you send a message in HTML, you might also want to provide a plain text version in case some of the recipients use e-mail readers that cannot display HTML content.

To add an alternate view to a MailMessage object, create an Attachment for the view, and then add it to the collection returned by AlternateViews. Use the Body property to specify the text version and use the AlternateViews collection to specify views with other MIME types. Use the MediaTypeNames class members to specify the MIME type for the alternate view.

11/28/2009 3:31:39 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

I'll do a little search on it and let you know. The idea is that the "Content-Transfer-Encoding" header has to be set, but if you were to set the header directly somehow I think you'd have to base64 the content yourself. I think best is to check out BodyEncoding property implementation in Mono [else maybe use .NET Reflector on MS impl. - latest one available by RedGate, still for free - might be able to show some info] to see how it sets the TransferEncoding to base64 when the BodyEncoding is UTF-8/UTF-16/UTF-32 (I hope that they use some public calls to do that, not under the hood trickery).

11/28/2009 3:32:42 PM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

All of that sounds like a lot of complicated work, if you are interested in trying to implement it I will let you know once my current changes are in svn trunk. I did encode the subject same as the body as I saw that property and figured it needed to be the same.

The display name encoding issue also sounds like non trivial work, if that is important for you perhaps you would be willing to implement it.

For me these are not high priorities. I'm sure OSCommerce and others already have support for it and someday we will too, but in the grand scheme of things the mojoPortal WebStore needs a lot of things much more important than display name support in email as does mojoPortal in general. I need to stay on the priorities that I see as more important.

Best,

Joe

11/28/2009 3:34:44 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

I don't mind implementing it myself, I want to start playing with mojoPortal's code anyway and maybe it's a good chance to do it...

11/28/2009 3:36:25 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

Does mojoPortal support HTML mails that have fallback plain text currently? (as AlternateViews [MIME/Multipart])

11/28/2009 3:36:54 PM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

Awesome! I just started the merge, it will take several hours. I'll post again when it is complete.

Best,

Joe

11/28/2009 3:39:22 PM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

Does mojoPortal support HTML mails that have fallback plain text currently? (as AlternateViews [MIME/Multipart])

No, since that is not supported directly/easily on the .NET classes (as far as I know). DotNetOpenMail had that which was one of the things that attracted me to it originally. 

If you feel you can implement this as well it would be welcome help!

Best,

Joe

11/28/2009 3:43:30 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

at

http://community.discountasp.net/showthread.php?t=3762

there's a useful discussion that shows one can have a message with just a text/plain AlternateView, so they can set TransferEncoding there (modified their sample a bit since they were instantiating SmtpClient class twice by accident)

MailMessage email = new MailMessage(SENDER_EMAIL, RECIPIENT_EMAIL);

email.Subject = SUBJECT;

AlternateView plainView = AlternateView.CreateAlternateViewFromString(sMessageBody, Nothing, "text/plain");

plainView.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;

email.AlternateViews.Add(plainView);

SmtpClient _client;

this._client = new SmtpClient(SMTP_SERVER, 25);

this._client.Credentials = new NetworkCredential(CRED_ID, CRED_LOGIN);

this._client.Timeout = TIMEOUT;

this._client.Send(email);



11/28/2009 3:48:21 PM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

Well that looks easy enough ;-) and will be very useful.

11/28/2009 3:48:58 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

There's a CreateAlternateViewFromString that takes an encoding param (the example I used above had Nothing for the encoding)

http://msdn.microsoft.com/en-us/library/ms144596.aspx

so one can add an AlternateView of "text/plain" with the encoding the user asked and then tell it to use "base64" TransferEncoding (in the example I copy/pasted above they were using 7-bit)

----

Also in the same way can add more AlternateViews for HTML mimetype ("text/html" I think is the MIME type, but better check it out). For HTML with no images/attachments (just formatted text) it's easy to add with few changes I suppose

11/28/2009 3:52:31 PM
Gravatar
Total Posts 116
http://www.zoomicon.com http://birbilis.spaces.live.com http://www.delicious.com/birbilis http://twitter.com/Zoomicon

Re: non useful log about wrong e-mail address format

regarding the SubjectEncoding you just do as before I suppose, set the appropriate property of the MailMessage class (the AlternateViews are for the content, not the header)

11/29/2009 7:05:50 AM
Gravatar
Total Posts 18439

Re: non useful log about wrong e-mail address format

My changes from yesterday are now in svn trunk so you can proceed with the improvements you want to work on. The relevant code is in the mojoPortal.Net project Email.cs.

If you add support for a from address display name to be passed in you should create a new overload.

Currently there are methods named SendEmail which use the DotNetOpenMail library and SendEmailNormal which use the System.Net classes.

Ultimately once everything is working and tested using various encodings I will move the system.net logic into the SendEmail methods and deprecate the SendEmailNormal methods and remove references to DotNetOpenMail.

Once you have completed your enhancements for encodings and display name and they have been tested thoroughly, then I will do the work to add a setting in the WebStore for the email display name and I will also add it as a site setting so it can be used more generally in other site emails.

You can create an svn patch and send it to me when you are finished.

Thanks for your help with this!

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.