System.Net.Mail参考不存在 [英] System.Net.Mail reference does not exist

查看:178
本文介绍了System.Net.Mail参考不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,创建应用程序发送电子邮件。

I have a problem creating application to send email.

我已经有一个工作作为一个Windows窗体应用程序,然后决定做从空项目一样,因为我需要一个后台应用程序现在。

I already have one working as a Windows Forms Application and then decided to do the same from the empty project, because I need to make a background application now.

我用了 System.Net.Mail 命名空间的Windows窗体。然后添加相同的代码到新的项目。

I used the System.Net.Mail namespace for that in a Windows Forms. Then added the same code to the new project.

不过,我得到以下错误:

However, I get the following error:

类型或命名空间名称邮件不会在命名空间
'System.Net'存在。

The type or namespace name 'Mail' does not exist in the namespace 'System.Net'.

System.Net参考包括在项目引用列表,我无法找到可能的引用列表命名为System.Net.Mail任何东西。问题的关键是,我没有这些错误在Windows窗体应用程序。

The 'System.Net' reference is included in the project references list and I can't find anything named 'System.Net.Mail' in the list of possible references. The point is that I didn't have those errors in Windows Forms app.

推荐答案

我试图重现这在Visual Studio 2012,但即使当我设置编译器使用 .NET 2.0我还没有遇到这个问题。

I tried to reproduce this in Visual Studio 2012, but even when I set the compiler to use .NET 2.0 I still did not encounter this issue.

这可能是你缺少了系统参考.DLL ,其中包括命名空间 System.Net.Mail 。正如你没有包含任何示例代码,我将包括一个简单实现一个邮件客户端作为例子的预防措施。

It is possible that you are missing the reference for System.dll which includes the namespace System.Net.Mail. Just as an precaution as you didn't include any sample code I will include a simple implementation of a Mail client as an example.

using (SmtpClient client = new SmtpClient("smtp-server.MyDomain.com"))
{
    client.UseDefaultCredentials = true;

    using (MailMessage mail = new MailMessage())
    {
        mail.Subject = subject;
        mail.Body = body;

        mail.From = new MailAddress("MyEmail@MyDomain.com");
        mail.To.Add("ToThisEmail@MyDomain.com");

        client.Send(mail);
    }
}



虽然我没有能够重现这个我仍然建议您确认您正在编译您对同一目标框架,以前的客户端项目。

Even though I wasn't able to reproduce this I would still recommend that you verify that you are compiling your project against the same target framework as your previous client.

您可以在您的项目并选择右击做到这一点目标框架应用标签。

You can do this by right-clicking on your project and selecting Target framework under the Application tab.

编辑:这可能是值得考虑你当前的引用的屏幕截图,并在这里计算器上传。它将给我们的潜在问题或冲突的更好的概览。

It might be worth taking a screenshot of your current references and uploading it here at stackoverflow. It would give us an better overview of potential issues or conflicts.

有应该没有必要修改的App.config ,但作为这里的参考,你有我

There should be no need to modify your App.config, but as a reference here you have mine.

<?xml version="1.0"?>
<configuration>
    <startup> 
    <supportedRuntime version="v2.0.50727"/></startup>
</configuration>



EDIT2:

添加 System.dll中引用。

Add the System.dll reference.


  1. 右键点击您的项目,并选择添加引用

  2. 找到并添加系统(或 System.dll中)在组件框架

  3. 点击确定保存。

  1. Right click on your project and choose Add Reference.
  2. Find and add System (or System.dll) under Assemblies and Framework.
  3. Click OK to save.

这篇关于System.Net.Mail参考不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆