Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 发送SMTP邮件时XML文件中的奇怪字符_C#_Xml_Email_Smtp_Email Attachments - Fatal编程技术网

C# 发送SMTP邮件时XML文件中的奇怪字符

C# 发送SMTP邮件时XML文件中的奇怪字符,c#,xml,email,smtp,email-attachments,C#,Xml,Email,Smtp,Email Attachments,我试图通过电子邮件发送XML文件,但当我在收件箱中收到邮件时,XML声明中会弹出“3D” 这就是我的XML文件序列化时的样子 <?xml version="1.0"?> <PositionOpeningNL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"></<PositionOpeningNL> 问题在

我试图通过电子邮件发送XML文件,但当我在收件箱中收到邮件时,XML声明中会弹出“3D”

这就是我的XML文件序列化时的样子

<?xml version="1.0"?>
<PositionOpeningNL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"></<PositionOpeningNL>

问题在于我使用的服务。我用office365取代了mailtrap,角色不再出现了。我还注意到,这两种服务中的附件都没有问题。邮件的原始输出很可能使其看起来像文件中的字符。

问题在于我使用的服务。我用office365取代了mailtrap,角色不再出现了。我还注意到,这两种服务中的附件都没有问题。邮件的原始输出很可能使其看起来像文件本身中的字符。

您已经有了正确格式的xml文件了吗?如果是这样,则不需要再次序列化它。将xml文件附加到电子邮件,而不重新序列化。这并不能解决我的问题,但无论如何,感谢您指出它。您已经拥有正确格式的xml文件了吗?如果是这样,则不需要再次序列化它。将xml文件附加到电子邮件,而不重新序列化。这并不能解决我的问题,但无论如何,感谢您指出这一点。
From: db6faa544039df <********-ef6b15@inbox.mailtrap.io>
Date: Fri, 15 Mar 2019 10:01:20 +0100
Subject: XML
Message-Id: <****************@DESKTOP-*********>
To: Mo <e-mail>
MIME-Version: 1.0
Content-Type: text/xml; name=debug.xml
Content-Disposition: attachment; filename=debug.xml
Content-Transfer-Encoding: quoted-printable

<?xml version=3D"1.0"?>
<PositionOpeningNL xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-insta=
nce" xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema">
  </PositionOpeningNL>
using System;
using System.Xml.Serialization;
using System.IO;
using System.Data.SqlClient;
using MailKit;
using MailKit.Net.Smtp;
using MimeKit;
public class PositionOpeningNL
{

}

 var convert = new PositionOpeningNL();
 var serializer = new XmlSerializer(convert.GetType());

            //serializer.Serialize(Console.Out, convert);
            using (FileStream fs = new FileStream(Environment.CurrentDirectory + "//debug.xml",
                FileMode.Create, FileAccess.Write))
            {
                serializer.Serialize(fs, convert);
                //MessageBox.Show("Created");
            }

            var message = new MimeMessage();
            var builder = new BodyBuilder();
            message.From.Add(new MailboxAddress("db6faa544039df", "******-ef6b15@inbox.mailtrap.io"));
            message.To.Add(new MailboxAddress("Mo", "e-mail"));
            message.Subject = "XML";
            builder.Attachments.Add(Environment.CurrentDirectory + "//debug.xml");
            message.Body = builder.ToMessageBody();
            //message.Attachments = ser;
            using (var client = new SmtpClient())
            {

                client.ServerCertificateValidationCallback = (s, c, h, f) => true;

                client.Connect("smtp.mailtrap.io", 465, false);
                client.Authenticate("username", "password");
                client.Send(message);
                client.Disconnect(true);

            }