任何人都可以整理以下代码,以便向电子邮件添加附件吗?
谢谢
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="ISO-8859-1" Debug="true" %>
<% @Import Namespace="System.Web.Mail" %>
<% @Import Namespace="IO" %>
<script language="vb" runat="server">
Sub btnSendEmail_Click(sender as Object, e as EventArgs)
Dim objMM as New MailMessage()
objMM.To = "my@email.co.uk"
objMM.From = "their@email.co.uk"
objMM.BodyFormat = MailFormat.HTML
objMM.Priority = MailPriority.Normal
objMM.Subject = "Attachment test"
objMM.Body = "There should be an attachment with this email"
objMM.Attachments.Add(new MailAttachment("myimage.jpg"))
SmtpMail.SmtpServer = "localhost"
SmtpMail.Send(objMM)
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:Button runat="server" id="btnSendEmail" Text="Send email" OnClick="btnSendEmail_Click" />
</form>
</body>
</html>
最佳答案
我对此表示怀疑
new MailAttachment("myimage.jpg")
我怀疑您可能想要获取完整路径,例如
new MailAttachment(Server.MapPath("Myimage.jpg"))
关于asp.net - 添加附件到电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3786065/