gpt4 book ai didi

asp.net - 添加附件到电子邮件

转载 作者:行者123 更新时间:2023-12-02 18:42:01 24 4
gpt4 key购买 nike

任何人都可以整理以下代码,以便向电子邮件添加附件吗?

谢谢

<%@ 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com