I have a problem creating application to send email.
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.
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:
The type or namespace name 'Mail' does not exist in the namespace 'System.Net'.
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.
Allows applications to send email by using the Simple Mail Transfer Protocol (SMTP). The SmtpClient type is obsolete on some platforms and not recommended on others; for more information, see the Remarks section.
It is not obsolete in . NET Framework 4.7. It was inadvertently documented as such in the API Browser due to a bug in the automated documentation generator. However, it is obsolete in Mono and Xamarin.
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("[email protected]");
mail.To.Add("[email protected]");
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.
Add Reference
. System
(or System.dll
) under Assemblies
and Framework
. OK
to save.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With