【问题标题】:need to send xml format in the mail需要在邮件中发送xml格式
【发布时间】:2017-10-29 11:00:11
【问题描述】:

我正在尝试发送邮件。在正文部分,当我使用 html 格式时,它按原样呈现。实际上,它存储在一个 xml 文件中,所以我如何发送该 xml 格式,以便当有人收到邮件时将以正确的格式显示。

网络服务代码

  public Thankyou()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 

        MailMessage o = new MailMessage("esh_p07@hotmail.com", "esh07@gmail.com", "Event Inquiry", @"< html >
< head >< title >[#text:@@hotelname#] Event Inquiry Form</title></head>
< body >
< h1 style = ""font - family:Verdana, Arial, Helvetica, sans - serif; font - weight:normal; font - size:14px; "" > You have received an email via the < b >[Culver Hotel </ b > Event Inquiry form.</ h1 >
          < h2 style = ""font - family:Verdana, Arial, Helvetica, sans - serif; font - weight:normal; font - size:12px; "" >
                    < b > From: </ b >[#text:contact_name#] <a href=""mailto:[#text:contact_email#]"" >[#text:contact_email#]</a><br>
< b > Phone: </ b > [#text:contact_phone#]<br>
< b > Requested Date: </ b > [#text:rfp_requestmonth#] [#text:rfp_requestdate#],[#text:rfp_requestyear#]<br>
< b > Requested Time: </ b > [#text:requested_time#]<br>
< b > Number of Guests: </ b > [#text:number_guests#]<br>
< b > Comments: </ b >< br > [#text:contact_comments#]
</ h2 >
                      </ body >
                      </ html >");
        NetworkCredential netCred = new NetworkCredential("user@example.com", "pAssw0rd");
        SmtpClient smtpobj = new SmtpClient("wm.ebservices.com", 38);
        smtpobj.EnableSsl = false;
        smtpobj.Credentials = netCred;
        smtpobj.Send(o);


    }

这是以 xml 格式存储的正文格式,我希望当有人收到邮件时,它会以正确的格式显示,目前我正在接收带有 html 标记的消息

xml代码

<html>
<head><title>[#text:@@hotelname#] Event Inquiry Form</title></head>
<body>
<h1 style="font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:normal; font-size:14px;">You have received an email via the <b>[Culver Hotel</b> Event Inquiry form.</h1>
<h2 style="font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:normal; font-size:12px;">
<b>From: </b>[#text:contact_name#] <a href="mailto:[#text:contact_email#]" >[#text:contact_email#]</a><br>
<b>Phone: </b> [#text:contact_phone#]<br>
<b>Requested Date: </b> [#text:rfp_requestmonth#] [#text:rfp_requestdate#],[#text:rfp_requestyear#]<br>
<b>Requested Time: </b> [#text:requested_time#]<br>
<b>Number of Guests: </b> [#text:number_guests#]<br>
<b>Comments: </b><br> [#text:contact_comments#]
</h2>

</body>
</html>

【问题讨论】:

  • 您实际上是指 XML 还是您真的是在说 XHTML(或 HTML 5 plus XML,有时称为 XHTML5)?无论哪种方式,您可能都不想将其作为电子邮件的男孩发送,您应该从表单中提取数据以构建电子邮件并发送。
  • 实际上在此应用程序中,存储的数据以我在 xml 部分中显示的格式发送,但它在邮件中使用我不想要的所有 html 标签呈现,如何实现跨度>
  • 尝试其他响应,它可能会满足您的需求。我通常不使用 SOAP,所以我不能确定它是否正确。另外,我已经编辑了这个 Q 和你的另一个,以删除你不想要的东西。我希望这些修改很快就会获得批准。
  • 您可能有需要编码的特殊字符。使用 System.Net.WebUtility.HtmlDecode() 和/或 System.Net.WebUtility.HtmlEncode();见维基:google.com/…

标签: c# html asp.net xml web-services


【解决方案1】:

如果您需要使用您提供的数据使用网络服务创建 xml。您将需要使用 RPC 或文档的 SOAP 绑定来创建接口。然后添加接口的实现。 确保使用 @WebServe@SOAPBinding 注释添加和呈现您的 java 类。 比,您的实现类应该覆盖将以下数据添加为另一个类或单个变量的对象的方法。 :

<b>From: </b>[#text:contact_name#] <a href="mailto:[#text:contact_email#]" >[#text:contact_email#]</a><br>
<b>Phone: </b> [#text:contact_phone#]<br>
<b>Requested Date: </b> [#text:rfp_requestmonth#] [#text:rfp_requestdate#],[#text:rfp_requestyear#]<br>
<b>Requested Time: </b> [#text:requested_time#]<br>
<b>Number of Guests: </b> [#text:number_guests#]<br>
<b>Comments: </b><br> [#text:contact_comments#]

之后,您需要创建一个发布类并发布您的网络服务。点击您将在发布类中提到的 url,您将获得 xml 格式的数据。

然后您可以从 url 获取 xml 文件并按照您的方式邮寄。干杯!!!

【讨论】:

  • sahil 我不想 xml 我只希望我在正文部分发送的数据将出现在没有任何 标签的邮件中,因为它现在在邮件中使用标签呈现
  • 我想如果您想将邮件作为 html 格式的消息变量发送,那么您应该使用 javascript 首先获取标签内的数据并将这些变量保存到另一个消息变量中,然后发送邮件它。要获取 html 文档标签内的数据,您可以使用:var variable = document.createElement("DIV"); variable.innerHTML = b; and then return : variable.textContent || variable.innerText || "";
  • sahil 我明白你的意思,但无法完全实施,你能否提出更多建议。
  • 如果不是你想要或需要的答案,你为什么接受这个答案?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多