I found this code I want to run in a script, but I have this error:
Script compilation error: Cannot declare namespace in script code
I want to finish a function that to send a email by C#
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("[email protected]");
mail.To.Add("[email protected]");
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());
}
}
}
}
How can I do this?
scriptcsyourself. Please consider developing in a real IDE instead of using Notepad and compiling yourself. An IDE has many advantages...