使用C#发送邮件时出现问题

编程入门 行业动态 更新时间:2024-10-09 03:23:14
本文介绍了使用C#发送邮件时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

全部好, i我使用SMTP发送电子邮件,并通过文件上传控件将附件添加到电子邮件中,并通过邮件发送附件,但是对于第一个时间,如果我通过电子邮件发送文件邮件正确,但发送邮件后,如果我通过文件上传控件添加相同的文件,我会得到错误 该进程无法访问文件'D:\Program Files \Express\Temp \ SupportAttachments\ support.txt',因为它正被另一个进程使用。 我将文件从上传控件上传到网格,从网格中挑选文件并附加到邮件中。 /> 这是我的代码:

HI ALL, i am sending the email using SMTP and adding the attachements to the email from file upload control and sending the attachements with mail,but for the first time if i am sending the file through email the mail is going correctly but after sending the mail, for the secoind time if i am adding the same file through file upload control i am getting theerror "The process cannot access the file 'D:\Program Files\Express\Temp\SupportAttachments\support.txt' because it is being used by another process. " I am uploading the files from upload control to grid an dfrom grid picking the files and attaching to the mail.. here is my code:

foreach (GridViewRow gvrow in grdfiledetails.Rows) { Label lbl = (Label)gvrow.FindControl("lblfilename"); string SupportAttachmentFilePath = "D:\\Program Files\\Duck Creek Technologies\\Express\\Temp\\SupportAttachments"; SupportAttachmentFilePath += "\\" + lbl.Text; string BasePathValue = lbl.Text; firstAttachment = new Attachment(SupportAttachmentFilePath); firstAttachment = new Attachment(SupportAttachmentFilePath, MediaTypeNames.Application.Octet); mail.Attachments.Add(firstAttachment); //attach1 = BasePathValue; //firstAttachment.Dispose(); } try { SmtpServer.Send(mail);}<pre lang="c#">

请帮助该怎么做

Please help what to do

推荐答案

以前的流程尚未完成,这就是错误, 结束这个过程需要时间 r发送电子邮件后你就可以从代码中结束这个过程了。 它可以帮助你... Previous process has not been yet completed, thats y it is getting error, it takes time to end the process r else after sending email you end the process from code. it may helps you...

变量 firstAttachment 在foreach循环之外声明 - 改变它,在里面声明它。接下来,仅创建一次附件;还要确保没有重复项(两个文件名相同的附件)! The variable firstAttachment is declared outside the foreach loop - change that, declare it inside. Next, create the attachment only once; also make sure there are no duplicates (two attachments with the same filename)!

更多推荐

使用C#发送邮件时出现问题

本文发布于:2023-10-31 10:32:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545817.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送邮件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!