Thanks Stefan! I had no idea it would be so easy to implement. Your point about validation is a good one. I am already validating the Email field, but I should also validate the Name field so it doesn't have any funny stuff in it.
As described on Wikipedia,
To indicate for whom the message is intended, a user can use the "display name" of the recipient followed by the address specification surrounded by angled brackets, for example: John Smith <john.smith@example.org>
.
I ran into trouble with that with the error log showing
InnerException: An invalid character was found in the mail header: '>'.
Method: System.Net.Mail.DotAtomReader.ReadReverse
StackTrace:
Message: DotNetNuke.Services.Exceptions.ModuleLoadException: An invalid character was found in the mail header: '>'. ---> System.FormatException: An invalid character was found in the mail header: '>'. at System.Net.Mail.DotAtomReader.ReadReverse(String data, Int32 index) at System.Net.Mail.MailAddressParser.ParseDomain(String data, Int32& index) at System.Net.Mail.MailAddressParser.ParseAddress ...
Therefore, I tried an experiment where I just used the Email field as the sole input to the calculated field. The expression was [Email]
The result was another error in the log:
The specified string is not in the form required for an e-mail address.
Method: System.Net.Mail.MailAddressParser.ParseAddress
StackTrace:
Message: DotNetNuke.Services.Exceptions.ModuleLoadException: The specified string is not in the form required for an e-mail address. ---> System.FormatException: The specified string is not in the form required for an e-mail address. at System.Net.Mail.MailAddressParser.ParseAddress(String data, Boolean expectMultipleAddresses, Int32& index) at System.Net.Mail.MailAddressParser.ParseAddress(String data) at System.Net.Mail.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding) at DotNetNuke.Services.Mail.Mail.SendMail(String mailFrom, String mailTo, String cc, String bcc, String replyTo, MailPriority priority, String subject, MailFormat bodyFormat, Encoding bodyEncoding, String body, List`1 attachments, String smtpServer, String smtpAuthentication, String smtpUsername, String smtpPassword, Boolean smtpEnableSSL) at ...
I think the calculated field may have an extra space added at the front and end, since appended characters show a spaces around the field value in the List mode when the calculate field is displayed. For example, an expression of '[<'+[Email]+'>]' produces this in the List: < joe@abc.com > and I can't seem to get rid of the spaces. So I am wondering if specifying the expression of [Email] produces " joe@abc.com " and that is perhaps what the MailAddressParser is complaining about.
Anyway, if it is complaining about a single space, it likely will not accept the Display Name before the address either. So maybe this plan won't work afterall.
Any thoughts?
Thanks again for your insights.