我是C#编码的新手,当我运行查询时,我遇到了:脚本编译错误:无法在脚本代码中声明命名空间
我想完成一个由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("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());
}
}
}
}
答案 0 :(得分:0)
感谢大家在这个博客上的帮助。 我只是想出了自己,只需使用纯功能代码,效果很好。
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);