Email subject problem
I am using MailMessage class in my program. When the subject is too long subject will look like.
Subject:
=?utf-8?B?W0VudGVycHJpc2UgUHJpb3JpdHldIC0gQ3VzdG9tZXIgSW5jaWRlbnQgNjkxNzIgZm9yIEhhcmlkaGFyYW4gKDEzMjM5OSkgaGFyaWRoYXJhbnJAc3luY2Z1c2lvbi5jb20gOiBUZXN0aW5nIFRlc3RpbmcgVGVzdGluZyBUZXNpbmcgVGVzdGluZyBUZXN0aW5nIFRlc3RpbmcgVGVzdGluZyBUZXN0aW5nIFRlc3Rpbmcg4o"
This problem occurred in server only. while debugging i have used the same subject content in my "local" but, i got correct subject.
Program:
protected MailMessage msg;
msg.Subject = s开发者_高级运维ubject;
Got the same (error) subject in WebMail.IHostExchange.NET also.
What is the problem?
Update:
This is a part of my coding.
public EmailSenderThread(string emailAddresses, string ccemailaddress, string from, string subject, string body)
: base()
{
msgThread = new Thread(new ThreadStart(MailSender));
this.mailAddress = emailAddresses;
this.ccmailAddress = ccemailaddress;
msg.From = new MailAddress(from);
msg.IsBodyHtml = true;
msg.Body = body;
string[] mails = emailAddresses.Split(';');
foreach (string mail in mails)
if (!string.IsNullOrEmpty(mail))
msg.To.Add(mail);
if (ccemailaddress != string.Empty)
{
string[] ccemails = ccemailaddress.Split(';');
foreach (string ccmail in ccemails)
if (!string.IsNullOrEmpty(ccmail))
msg.CC.Add(ccmail);
}
msg.Subject = subject;
msgThread.Start();
}
I have already tried with
msg.SubjectEncoding = System.Text.Encoding.UTF8;
but i got the same error. Did you got my doubt. Please let me know if I didn't explain clearly.
1) why it is working fine in local? and why it is not working when i am hosting this into server. ?
2) What is the maximum length of the subject line?
2) What is the maximum length of the subject line?
From RFC822 about unstructured header fields:
Some field bodies in this standard are defined simply as "unstructured" (which is specified below as any US-ASCII characters, except for CR and LF) with no further restrictions. These are referred to as unstructured field bodies. Semantically, unstructured field bodies are simply to be treated as a single line of characters with no further processing (except for header "folding" and "unfolding" as described in section 2.2.3).
The subject line is an unstructured field, and therefore has no imposed length limit.
Without seeing more code, I'm going to guess an encoding problem - try specifying an encoding for your subject and body. Look at this post for sample code.
精彩评论