相关疑难解决方法(0)

SMTP发送锁定了我的文件 - c#

我有一个功能,发送消息(很多)和他们的附件.

它基本上循环遍历目录结构,并从文件结构创建电子邮件

 c:\emails\message01
                \attachments
 c:\emails\message02
                \attachments
Run Code Online (Sandbox Code Playgroud)

使用.net c#,标准内容创建消息.

创建所有消息后......我有另一个直接运行的函数,它将消息文件夹复制到另一个位置.

问题是 - 文件被锁定了......

注意:我没有移动文件,只是复制它们....

有关如何使用c#复制锁定文件的任何建议?

更新

我有这个添加附件方法

    private void AddAttachments(MailMessage mail)
    {
        string attachmentDirectoryPath = "c:\messages\message1";
        DirectoryInfo attachmentDirectory = new DirectoryInfo(attachmentDirectoryPath);
        FileInfo[] attachments = attachmentDirectory.GetFiles();
        foreach (FileInfo attachment in attachments)
        {
            mail.Attachments.Add(new Attachment(attachment.FullName));
        }
    }
Run Code Online (Sandbox Code Playgroud)

c# smtp locked-files

23
推荐指数
2
解决办法
1万
查看次数

c#File.Delete - 另一个进程正在使用的文件

我有一个小的电子邮件程序,它进行加密.以下只是该计划的摘要:

private void sendEmailButton_Click(object sender, EventArgs e)
{
    else
    {    
        //////////////////////////////////////////////////////////////////////////
        if (encryptEverythingCheckBox.Checked)
        {
            encryptAll();
        }
        //////////////////////////////////////////////////////////////////////////

        // Email credentials network codes blahblah
        // Assign the sender's email address to MailAddress function
        MailAddress mailAddress = new MailAddress(username);
        // Tells the recipent the sender's email
        mailMessage.From = mailAddress;
        // Username & Password of your email address
        System.Net.NetworkCredential networkCredential;
        networkCredential = new System.Net.NetworkCredential(username, password);
        // Enable SSL to encypt the connection
        smtpClient.EnableSsl = true;
        // Disable the use of default credentials
        smtpClient.UseDefaultCredentials …
Run Code Online (Sandbox Code Playgroud)

c# encryption process

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×2

encryption ×1

locked-files ×1

process ×1

smtp ×1