C#编译不通过,Cannot declare namespace in script code
我是个C#新手,想要通过C#触发邮件,下面是一段C#的代码,当我运行时,报错:
Script compilation error: Cannot declare namespace in script code
using System;
using System.Windows.Forms;
using System.Net.Mail;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.sina.com");
mail.From = new MailAddress("noreply_test@sina.com");
mail.To.Add("blog_dev@sina.com");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from SINA";
SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential("hello", "world");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("mail Send");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}