JMail组件是否可通过GMail的Smtp发送邮件??
解决方案 »
- fck 内容禁止复制,剪切
- ⊙|⊙ASP.NET遍历客户端文件夹中文件⊙|⊙
- Petshop 连接字符串。
- vs.net2003自帶的CrystalReport,我注冊了一下就用不了了
- 困扰了偶三天!!服务器应用程序不可用!各种招数都用了,还是不行,高手帮忙啊,欲哭无泪了!
- 我做了一个网站,在我的电脑上很好.但是当我传到服务器上时出现如下错误。
- 提一个关于asp.net2.0的问题!
- ####一个简单的问题送你20分。
- 我问一下啊.怎么把文件上传到数据库的binary这个类型里啊..还有下载又怎么下载啊..
- 高分请教:ASP.NET 与JSP的前途哪个更好?
- 网站上传空间后出现Configuration Error
- vs2010 DataSet取数来源是存储过程时,无法取到临时表的列信息
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.Mail;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
sendSMforGMail("[email protected]", "akdkdls", "李明", "测试一下", "近来好吗?", "[email protected]");
}
private string sendSMforGMail(string sender, string pwd, string name, string SMtitle, string SMContent, string receiver)
{
//范例 sendSMforGMail("[email protected]","李明","测试一下","近来好吗?","[email protected]")
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
// msg.To.Add(phonenumber + "@139.com");
msg.To.Add(receiver);
//msg.To.Add("");
//msg.To.Add("[email protected]");
/*
* msg.To.Add("[email protected]");
* msg.To.Add("[email protected]");
* msg.To.Add("[email protected]");可以发送给多人
*/
//msg.CC.Add("抄送地址");
/*
* msg.CC.Add("[email protected]");
* msg.CC.Add("[email protected]");可以抄送给多人
*/
msg.From = new MailAddress(sender, name, System.Text.Encoding.UTF8);
/* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/
msg.Subject = SMtitle;//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = SMContent;//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = false;//是否是HTML邮件
// msg.Priority = MailPriority.High;//邮件优先级 SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential(sender, pwd);
//上述写你的邮箱和密码
client.Port = 587;//gmail 使用的端口
client.Host = "smtp.gmail.com";
client.EnableSsl = true;//经过ssl加密
object userState = msg;
try
{
//client.SendAsync(msg, userState);
client.Send(msg);
//简单一点儿可以client.Send(msg);
// MessageBox.Show("发送成功");
//textBox2.Text = textBox2.Text + DateTime.Now.ToString() + " Have sent a message!" + "/r/n";
return "1";
}
catch (System.Net.Mail.SmtpException ex)
{
MessageBox.Show(ex.Message, "发送邮件出错");
// textBox2.Text = textBox2.Text + DateTime.Now.ToString() + " " + ex.Message + "/r/n";
return "0";
}
}
}
}