来自vb.net程序的电子邮件表 [英] Table in Email from vb.net program
问题描述
您好专家,
我创建了一个发送自动电子邮件的程序。
既然这个程序顺利进行,我还有一个来自客户的请求。他们应该在电子邮件中插入一个表格
我用过下面的代码e
mail.To。添加( b@b.com)
mail.CC.Add(ConfigurationManager。 AppSettings( FrmEmail))
mail.Subject = Re:出价状态为 + dr( Contractor)。ToString()
' Dim table As String =< table>< tr>< td> CMB#< / td>< td>作业名称< / td>< td>状态< / td>< / tr>< tr>< ; TD>中+ dr(Bid#)。ToString()+< / td>< td> + dr(Project).ToString()+< / td>< td> Yes / No / Not Yet< / td>< / tr>< / table> +< p>< br />< br />< / p>
' Dim thanksmsg As String = < table>< tr>< td>
mail.IsBodyHtml = True
Dim strb As 字符串 = 字符串 .Empty
strb = strb& < html>< body>< p>< / p>
strb = strb& < table width ='70%'border ='1'cellpadding ='0'cellspacing ='0'bgcolor ='white'>
strb = strb& < tr>
strb = strb& < td> CMB#< / td>
strb = strb& < td>作业名称< / td>
strb = strb& < td>状态< / td>
strb = strb& < / tr>
strb = strb& < tr>
strb = strb& < td> + dr( 出价#)+ < / td> ;
strb = strb& < td> + dr( 项目)+ < / td>
strb = strb& < td>< / td>
strb = strb& < / tr>
strb = strb& < / table>
strb = strb& < / body>
strb = strb& < / html>
' Dim table As String =< table>< tr>< td> CMB#< / td>< td> ;作业名称< / td>< td>状态< / td>< / tr>< tr>< td> + dr(Bid#)。ToString()+< / td>< td> + dr(Project).ToString()+< / td>< td> Yes / No / Not Yet< / td>< / tr>< / table> +< p>< br />< br />< / p>
' Dim thanksmsg As String = < table>< tr>< td>
Dim body As String = 嗨 + Environment.NewLine + 请让我知道以下工作的状态 + Environment.NewLine + strb.ToString()
body = body& 如果您对此有任何疑问,请通过电子邮件与我联系。< BR />< BR />谢谢 + Environment.NewLine
body = body& ReadSignature( S.htm)& < p>< BR />< BR />< / p>
这个html没有创建带边框的表格。它就像一句话就像一行一样
你能帮我吗
添加元素头
。在此元素中,添加元素样式
。使用CSS添加边框和其他样式属性。对于最小的基本格式,请使用类似
td {border:solid thin black;
padding-left:1em; padding-right:1em;
}
对于非常漂亮的外观,你需要添加更多,但它不会太多。非常简单。
请注意,您可以使用多个部分创建更复杂的HTML,而不是使用IsBodyHtml
。那么HTML部分应该有 content-type :text / html。
请参阅:
https://msdn.microsoft.com/en-us/library/system .net.mail.mailmessage.attachments%28v = vs.110%29.aspx [ ^ ],
https://msdn.microsoft.com/en-us/library/system .net.mail.mailmessage.alternateviews%28v = vs.110%29.aspx [ ^ ],
https://msdn.microsoft.com /en-us/library/system.net.mail.mailmessage.alternateviews%28v=vs.110%29.aspx [ ^ ],
< a href =https://msdn.microsoft.com/en-us/library/system.net.mail.attachment%28v=vs.110%29.aspx> https://msdn.microsoft.com/en -us / library / system.net.mail.attachment%28v = vs.110%29.aspx [ ^ ],
https://msdn.microsoft.com/en-us/library /system.net.mail.attachmentbase.contenttype%28v=vs.110%29.aspx [ ^ ],
https://msdn.microsoft.com/en-us/library/system.net .mail.attachment.contentdisposition%28v = vs.110%29.aspx [ ^ ]。
注意ContentDisposition
是另一件重要的事情。您可以使部件显示为内联,或仅可下载(附件),
https://msdn.microsoft.com/en-us/library/system.net.mime.contentdisposition%28v=vs.110%29.aspx [ ^ ],
https://msdn.microsoft.com/en-us/library/system.net.mime.contentdisposition.dispositiontype%28v=vs.110%29.aspx [ ^ ],
https://msdn.microsoft.com/en-us/l ibrary / system.net.mime.dispositiontypenames%28v = vs.110%29.aspx [ ^ ]。
-SA
Hello experts,
I have created a program which sends automatic emails.
Now that this program is going on smoothly I have got one more request from client . They should insert a Table in the email
I have used below cod e
mail.To.Add("b@b.com")
mail.CC.Add(ConfigurationManager.AppSettings("FrmEmail"))
mail.Subject = "Re: Bid status of " + dr("Contractor").ToString()
' Dim table As String = "<table><tr><td>CMB#</td><td>Job Name</td><td>Status</td></tr><tr><td>" + dr("Bid #").ToString() + "</td><td>" + dr("Project ").ToString() + "</td><td>Yes/ No / Not Yet</td></tr></table>" + "<p><br/> <br/></p>"
'Dim thanksmsg As String = "<table><tr><td>"
mail.IsBodyHtml = True
Dim strb As String = String.Empty
strb = strb & "<html><body><p></p>"
strb = strb & "<table width='70%' border='1' cellpadding='0' cellspacing='0' bgcolor='white'>"
strb = strb & "<tr>"
strb = strb & "<td> CMB# </td>"
strb = strb & "<td> Job Name </td>"
strb = strb & "<td> Status </td>"
strb = strb & "</tr>"
strb = strb & "<tr>"
strb = strb & "<td>" + dr("Bid #") + "</td>"
strb = strb & "<td>" + dr("Project ") + "</td>"
strb = strb & "<td></td>"
strb = strb & "</tr>"
strb = strb & "</table>"
strb = strb & "</body>"
strb = strb & "</html>"
'Dim table As String = "<table><tr><td>CMB#</td><td>Job Name</td><td>Status</td></tr><tr><td>" + dr("Bid #").ToString() + "</td><td>" + dr("Project ").ToString() + "</td><td>Yes/ No / Not Yet</td></tr></table>" + "<p><br/> <br/></p>"
' Dim thanksmsg As String = "<table><tr><td>"
Dim body As String = "Hi" + Environment.NewLine + "Please let me know status of the below job" + Environment.NewLine + strb.ToString()
body = body & "Please contact me, by e-mail, if you have any difficulties with this.<BR/><BR/> Thanks" + Environment.NewLine
body = body & ReadSignature("S.htm") & "<p><BR/><BR/></p>"
This html is not creating a table with borders. It just comes in one line like a sentence
Could you please help me
Add the elementhead
. In this element, add the elementstyle
. Use CSS to add borders and other style properties. For minimal, rudimentary formatting, use something like
td { border: solid thin black; padding-left: 1em; padding-right: 1em; }
For really nice look, you would need to add a lot more, but it won't be too much. Pretty easy.
Note that instead of usingIsBodyHtml
, you can create more complicated HTML, with multiple parts. Then HTML parts should have content-type: "text/html".
Please see:
https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.attachments%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.alternateviews%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.alternateviews%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.net.mail.attachment%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.net.mail.attachmentbase.contenttype%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.net.mail.attachment.contentdisposition%28v=vs.110%29.aspx[^].
Note thatContentDisposition
is another important thing. You can make the part shown inline, or downloadable only ("attachment"),
https://msdn.microsoft.com/en-us/library/system.net.mime.contentdisposition%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.net.mime.contentdisposition.dispositiontype%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.net.mime.dispositiontypenames%28v=vs.110%29.aspx[^].
—SA
这篇关于来自vb.net程序的电子邮件表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!