62,074
社区成员
发帖
与我相关
我的任务
分享
SmtpClient smtp = new SmtpClient("smtp服务器地址");
smtp.Credentials = new System.Net.NetworkCredential("你的用户名", "你的密码");
MailMessage mes = new MailMessage();
mes.From = new MailAddress("发送者的邮件地址");
mes.To.Add("发给谁的邮件地址");
mes.Subject = "主题";
mes.Body = "邮件内容";
mes.IsBodyHtml = true;
smtp.Send(mes);
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="TABLE1" runat="server" border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 393px">
收信:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
主题:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
内容:<asp:TextBox ID="TextBox3" runat="server" Height="154px" TextMode="MultiLine"
Width="336px"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="发送" OnClick="Button1_Click" /></td>
</tr>
</table>
</div>
<table id="Table2" runat="server" border="0" cellpadding="0" cellspacing="0" visible="false">
<tr>
<td align="center" style="width: 400px">
<asp:Label ID="Label1" runat="server" ForeColor="Red" Text="恭喜您,发表成功!"></asp:Label><br />
<asp:Button ID="Button2" runat="server" Text="返回" OnClick="Button2_Click" /></td>
</tr>
</table>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;
public partial class sendMail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
////设置发件人信箱,及显示名字
MailAddress from = new MailAddress("lichuan3@126.com", "J.L.C");
//设置收件人信箱,及显示名字
MailAddress to = new MailAddress(TextBox1.Text, "JLC");
//创建一个MailMessage对象
MailMessage oMail = new MailMessage(from, to);
oMail.Subject = TextBox2.Text; //邮件标题
oMail.Body = TextBox3.Text; //邮件内容
oMail.IsBodyHtml = true; //指定邮件格式,支持HTML格式
oMail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");//邮件采用的编码
oMail.Priority = MailPriority.High;//设置邮件的优先级为高
//发送邮件服务器
SmtpClient client = new SmtpClient();
client.Host = "smtp.126.com"; //指定邮件服务器
client.Credentials = new NetworkCredential("lichuan3@126.com", "jlc3509589934");//指定服务器邮件,及密码
//发送
try
{
client.Send(oMail); //发送邮件
Label1.Text = "恭喜你!邮件发送成功。";
}
catch
{
Label1.Text = "邮件发送失败,检查网络及信箱是否可用。";
}
oMail.Dispose(); //释放资源
TABLE1.Visible = false;
Table2.Visible = true;
}
protected void Button2_Click(object sender, EventArgs e)
{
//返回,继续发送
Response.Redirect(Request.Url.ToString());
TABLE1.Visible = true;
Table2.Visible = false;
}
}
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Mail;
namespace gqlm
{
public class SendMail
{
public SendMail()
{
//
}
private static string _Host = "mail.yourdomain.com";
private static string _SmtpMailName = "support@yourdomain.com";
private static string _SmtpMailPassWord = "MailPassWord";
public static bool SendMailTo(string mailto, string mailtoname, string mailsubject, string mailbody, string mailFrom, string fromname)
{
try
{
//编码暂硬性规定为GB2312
Encoding encoding = Encoding.GetEncoding(936);
MailMessage Message = new MailMessage(
new MailAddress(mailFrom, fromname, encoding),//第一个是发信人的地址,第二个参数是发信人名称
new MailAddress(mailto));//收信人邮箱
Message.SubjectEncoding = encoding; //编码
Message.Subject = mailsubject; //标题
Message.BodyEncoding = encoding;
Message.Body = mailbody; // "<font size='16px' color='red'>这是一封测设邮件</font>"; //主体
Message.IsBodyHtml = true;
SmtpClient smtpClient = new SmtpClient(_Host);//信箱服务器
smtpClient.Credentials = new NetworkCredential(_SmtpMailName, _SmtpMailPassWord);//信箱的用户名和密码
smtpClient.Timeout = 999999;
smtpClient.Send(Message);
}
catch
{
// throw new Exception(ex.Message);
return false;
}
return true;
}
}
}
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "SMTP.sina.com";
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("cn_csi@sina.com", "**********");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = false;
client.Timeout = 100000;
System.Net.Mail.MailMessage message = new MailMessage();
message.From = new MailAddress("cn_csi@sina.com", "康姆通专业设备有限公司");
message.To.Add(new MailAddress(Friends_Email.Value.Trim(), Friends_Name.Value.Trim()));
message.Subject = "你的朋友: " + Your_Name.Value.Trim() + " 向你推荐一款产品";
message.Body = messagetext.Value +" 产品名称:"+ productsname.Text;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
try
{
client.Send(message);
Label1.Visible = true;
this.Label1.Text = "邮件已经发送";
}
catch
{
}