0
나는 메일 발신자 생성기를 만들고 싶다. 하지만 난 codesom 참조에 문제가있다. 내 결과는 다음과 같습니다 " 'System.Net'네임 스페이스에 'Mail'유형 또는 네임 스페이스 이름이 없습니다. 어셈블리 참조가 누락 되었습니까?"codesom add reference
시스템 때문에 system.net.mail을 추가 할 수 없습니다. net.mail은 dll 파일이 아닙니다. 내 코드 : 내가 가지고있는
using System;
using System.Collections.Generic;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.Runtime.InteropServices;
namespace compilerTest
{
class Program
{
static void compileIt1()
{
//mail sender code
string source =
@"
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
using System.Net;
namespace mail_sender
{
class Program
{
static void Main(string[] args)
{
SmtpClient smtp = new SmtpClient(""smtp.gmail.com"", 587);
NetworkCredential myCredentials = new NetworkCredential(""[email protected]"", ""password"");
smtp.Credentials = myCredentials;
smtp.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, ssl) => true;
smtp.Send(""[email protected]"", ""[email protected]"", ""titel"", ""mail body"");
Console.ReadKey();
}
}
}
";
//version
Dictionary<string, string> providerOptions = new Dictionary<string, string>
{
{"CompilerVersion", "v3.5"}
};
//code type
CSharpCodeProvider provider = new CSharpCodeProvider(providerOptions);
//output file
CompilerParameters compilerParams = new CompilerParameters
{
OutputAssembly = "D:\\mailsender.EXE",
GenerateExecutable = true
};
compilerParams.ReferencedAssemblies.Add("System.Net.Dll");
//compile
CompilerResults results = provider.CompileAssemblyFromSource(compilerParams, source);
//errors
Console.WriteLine("Number of Errors: {0}", results.Errors.Count);
foreach (CompilerError err in results.Errors)
{
Console.WriteLine("ERROR {0}", err.ErrorText);
}
}
static void Main(string[] args)
{
compileIt1();
Console.WriteLine("Press a key...");
Console.ReadKey();
}
}
}
: .NET 3.5 VS 2010