需要在邮件中发送xml格式

时间:2017-05-29 07:57:12

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

我正在尝试发送邮件。在正文部分,当我使用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标签进行geeting消息

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>

1 个答案:

答案 0 :(得分:0)

如果您需要使用带有您提供的数据的Web服务创建xml。您需要使用SOAP绑定RPC或文档来创建接口。然后添加接口的实现。 确保使用 @WebSerive @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#]

之后,您需要创建一个发布类并发布您的webserice。点击您将在发布课程中提及的网址,您将获得xml格式的数据。

然后你可以从url获取xml文件并像你一样邮寄它。干杯!!!