Problem sending mail using System.Net.Mail C #

This is my mail sending code. I got the error "Invalid character in the mail header." When I changed the name of my computer to the shortest. The problem is resolved. But in my domain, the names of all computers, such as "04500-ab04545.xxxdomain.gov.tr", so I need to find another solution for this problem.

Therefore, I cannot give a static computer name when sending mail from C # code.

 MailMessage msg = new MailMessage();
 msg.Body = "axxxxxx";
 msg.To.Add(new MailAddress("xxxx@xxxx.domain"));
 msg.From = new MailAddress("xxxx@xxxx.domain","blab blalb");
 msg.Subject = "Subject xxx";
 SmtpClient server = new SmtpClient("xxxxxxxx",25);
 server.Credentials = new NetworkCredential("xxxxx", "xxxxxxx");
 SmtpClient server = new SmtpClient("mail.adalet.gov.tr",25);
 server.Credentials = new NetworkCredential("xxx", "xxx");
 server.Send(msg);
+3
source share
3 answers

I suspect this may be an encoding issue.

Try using the constructor new MailAddress("xxxx@xxxx.domain","blab blalb", Encoding.Default).

Please try again Encoding.Unicode.

Update:

:

void System.Net.BufferBuilder.Append(string,int,int);

, \xff . , , - , .

+4

?

MSDN:

string[] keys = message.Headers.AllKeys;
        Console.WriteLine("Headers");
        foreach (string s in keys)
        {
            Console.WriteLine("{0}:", s);
            Console.WriteLine("    {0}", message.Headers[s]);
0

I got this error, if this change was changed to "network" - then the error was resolved. (My understanding is to enable the specified pickupdirectory option, the -encoding utf-8 (base64) header gave an error)

Hope this helps

0
source

Source: https://habr.com/ru/post/1704155/


All Articles