System.Net.Mail reference does not exist

北城余情 提交于 2019-12-05 10:35:16

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.

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.

Edit: 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.

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:

Add the System.dll reference.

  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.

I faced the same issue. Following changes solved my problem. Change Target framework to .Net Framework 4 from .Net Framework 4 Client Profile.

Client Profile framework creates many such issues.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!