I'm trying to use OpenSMTP and I get the following subject line..
=?ISO-8859-1?Q?Contact Us - Comments?=
Any idea why this is happening? Am I doing something wrong? My code looks as follows...
EmailAddress senderAddress = new EmailAddress("webmaster@mysite.com");
EmailAddress recipientAddress = new EmailAddress("me@mysite.com");
MailMessage oMsg = new MailMessage(senderAddress, recipientAddress);
String subject = "Contact Us - Comments";
oMsg.Subject = subject;
String body = "Contact Us - Comments\n\n";
body += "Email: " + txtEmailFrom.Text + "\n";
body += "\n";
body += "Comments: " + txtComments.Text;
oMsg.Body = body;
Smtp smtp = new Smtp("ourSmtpServer", 2525);
smtp.SendMail(oMsg);
Keep in mind that this is all within a standard try/catch block in a C# code-behind module. Things like txtEmailFrom are obviously TextBox objects that have been initialized earlier. I didn't want to include all the code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OpenSmtp converts all the headers to Quoted-Printable. I hacked my version so that it only encodes the headers that need it by modifying ConvertHeaderToQP in MailEncoder.cs:
However, this changes the semantics of the call---it would be better to rename the method, or pass a parameter like "encodeIfNecessary". (And I'm not sure what would happen if you're using another character set.)
This won't fix the "To" field, because the code in CreateAddressList() is calling ConvertToQP(). You could do the same hack there....
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to use OpenSMTP and I get the following subject line..
=?ISO-8859-1?Q?Contact Us - Comments?=
Any idea why this is happening? Am I doing something wrong? My code looks as follows...
EmailAddress senderAddress = new EmailAddress("webmaster@mysite.com");
EmailAddress recipientAddress = new EmailAddress("me@mysite.com");
MailMessage oMsg = new MailMessage(senderAddress, recipientAddress);
String subject = "Contact Us - Comments";
oMsg.Subject = subject;
String body = "Contact Us - Comments\n\n";
body += "Email: " + txtEmailFrom.Text + "\n";
body += "\n";
body += "Comments: " + txtComments.Text;
oMsg.Body = body;
Smtp smtp = new Smtp("ourSmtpServer", 2525);
smtp.SendMail(oMsg);
Keep in mind that this is all within a standard try/catch block in a C# code-behind module. Things like txtEmailFrom are obviously TextBox objects that have been initialized earlier. I didn't want to include all the code.
OpenSmtp converts all the headers to Quoted-Printable. I hacked my version so that it only encodes the headers that need it by modifying ConvertHeaderToQP in MailEncoder.cs:
internal static string ConvertHeaderToQP(string s, string charset)
{
bool needsconversion=false;
for (int i=0; i<s.Length; i++)
{
if (s[i] > 126 || s[i] < 32)
{
needsconversion=true;
break;
}
}
if (!needsconversion)
{
return s;
}
return "=?" + charset + "?Q?" + ConvertToQP(s, charset) + "?=";
}
However, this changes the semantics of the call---it would be better to rename the method, or pass a parameter like "encodeIfNecessary". (And I'm not sure what would happen if you're using another character set.)
This won't fix the "To" field, because the code in CreateAddressList() is calling ConvertToQP(). You could do the same hack there....