本文介绍了电子邮件附件中的文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用文件上传控件在asp.net中为电子邮件附加文件?
目前,我正在使用硬编码路径发送附件,该附件是:
How do I use file upload control for attaching file for email in asp.net?
currently I am using the hard-coded path to send attachments which is :
Dim MyAttachment As Attachment = New Attachment("C:\Users\Admin\Desktop\EAIPJ(Coloré-Rachel,Peiwen,Sherry,Fiona)\Coloré\Images\BLACK SHATTER.jpg")
mail.Attachments.Add(MyAttachment)
我想对其进行更改,以便能够使用文件上载控件来选择文件的路径.我怎么做?
需要紧急帮助
I want to change it to be able to use file upload control to select the path of the file. How do I do that?
Urgent help is needed
推荐答案
if (FileUpload1.HasFile)
{
string toAddress = "you@yourprovider.com";
string fromAddress = "you@yourprovider.com";
string mailServer = "smtp.yourprovider.com";
MailMessage myMailMessage = new MailMessage();
myMailMessage.To.Add(toAddress);
myMailMessage.From = new MailAddress(fromAddress);
myMailMessage.Subject = "Test Message";
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
Attachment myAttachment =
new Attachment(FileUpload1.FileContent, fileName);
myMailMessage.Attachments.Add(myAttachment);
SmtpClient mySmtpClient = new SmtpClient(mailServer);
mySmtpClient.Send(myMailMessage);
}
Dim MyAttachment As Attachment = New Attachment(fileupload1.PostedFile.FileName)
mail.Attachments.Add(MyAttachment)
还要确保您的上传控件不在更新面板中.
-Amit
And also make sure that your upload control is not inside update panel.
--Amit
这篇关于电子邮件附件中的文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!