简体   繁体   English

电子邮件主题问题

[英]Email subject problem

I am using MailMessage class in my program. 我在程序中使用MailMessage类。 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 = subject;

Got the same (error) subject in WebMail.IHostExchange.NET also. WebMail.IHostExchange.NET中也有相同(错误)主题。

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? 1)为什么它在本地工作正常? and why it is not working when i am hosting this into server. 以及为什么当我将其托管到服务器时它不起作用。 ?

2) What is the maximum length of the subject line? 2)主题行的最大长度是多少?

2) What is the maximum length of the subject line? 2)主题行的最大长度是多少?

From RFC822 about unstructured header fields: 来自RFC822中有关非结构化标头字段的信息:

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. 该标准中的某些现场主体被简单地定义为“非结构化”(以下指定为任何US-ASCII字符,CR和LF除外),没有其他限制。 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). 从语义上讲,非结构化的字段主体仅被视为单行字符,无需进一步处理(如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 . 在这篇文章中查看示例代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM