|
楼主 |
发表于 2013-7-7 19:48:01
|
显示全部楼层
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
using System.Net.NetworkInformation;
namespace SMTPEMAIL
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
MailMessage aMessage = new MailMessage();
if (totextbox.Text == "")
{
MessageBox.Show("请填写收件人邮件地址");
}
else if (fromtextBox.Text == "")
{
MessageBox.Show("请填写发件人邮件地址");
}
else
{
aMessage = new MailMessage(fromtextBox.Text.Trim(), totextbox.Text.Trim());
string[] sep = fromtextBox.Text.Split(new Char[] { '@', '.' });
//组合SMTP服务器地址
string site = "smtp." + sep[1] + ".com";
SmtpClient client = new SmtpClient(site);
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(fromtextBox.Text.Trim(), userpsd.Text);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
//邮件主题
aMessage.Subject = subject.Text;
//邮件内容
aMessage.Body = bodytextbox.Text;
//发送电子邮件
client.Send(aMessage);
MessageBox.Show("邮件发送成功!");
}
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
这是代码 |
|