誰有發郵件的例子 散分(100分)
Dim msgObj As New EmailMessage
Dim server As New SMTPServer
Dim smtpObj As New SMTP msgObj.Subject = txtSubject.Text.Trim
msgObj.Recipients.Add("[email protected]", "matthew.mak", RecipientType.To) msgObj.From.Email = txtMail.Text.Trim
msgObj.From.Name = txtName.Text.Trim
msgObj.BodyParts.Add(txtContent.Text.Trim) server.Port = ( )------>端口是多少
server.Name = "mail.163.com"
server.Account = ""-------->這里寫什麼名字
server.Password = ""
server.AuthMode = SMTPAuthMode.AuthLogin smtpObj.SMTPServers.Add(server) Try
smtpObj.Send(msgObj)
lblmsg.Text = "成功 !"
Catch ex As LicenseException
lblmsg.Text = "License key error: " + ex.Message
Catch ex As FileIOException
lblmsg.Text = "File IO error: " + ex.Message
Catch ex As SMTPAuthenticationException
lblmsg.Text = "SMTP Authentication error: " + ex.Message
Catch ex As SMTPConnectionException
lblmsg.Text = "Connection error: " + ex.Message
End Try
Dim msgObj As New EmailMessage
Dim server As New SMTPServer
Dim smtpObj As New SMTP msgObj.Subject = txtSubject.Text.Trim
msgObj.Recipients.Add("[email protected]", "matthew.mak", RecipientType.To) msgObj.From.Email = txtMail.Text.Trim
msgObj.From.Name = txtName.Text.Trim
msgObj.BodyParts.Add(txtContent.Text.Trim) server.Port = ( )------>端口是多少
server.Name = "mail.163.com"
server.Account = ""-------->這里寫什麼名字
server.Password = ""
server.AuthMode = SMTPAuthMode.AuthLogin smtpObj.SMTPServers.Add(server) Try
smtpObj.Send(msgObj)
lblmsg.Text = "成功 !"
Catch ex As LicenseException
lblmsg.Text = "License key error: " + ex.Message
Catch ex As FileIOException
lblmsg.Text = "File IO error: " + ex.Message
Catch ex As SMTPAuthenticationException
lblmsg.Text = "SMTP Authentication error: " + ex.Message
Catch ex As SMTPConnectionException
lblmsg.Text = "Connection error: " + ex.Message
End Try
解决方案 »
- 菜鸟求助 asp.net关于时间类型方面的问题
- 正则表达式求解释!!!验证手机号
- asp.net 如何 include 其他文件
- button提交后弹出新页面问题
- // 在这里如何引用a这个变量?
- 关于$作用
- 这个字符串怎么写?
- 哪位前辈知道这个“用户 'NT AUTHORITY\NETWORK SERVICE' 登录失败”是什么错误吗?
- 思归!datagrid中的数据是否都会放在Hidden中?为什么查看页面代码时有一长串字符?
- 我在WEB.config中定义了strconnection,如何在index.aspx中引用???
- 求教:如何在类里访问Cookies?
- 如何把我的DB.CS文件生成DLL文件,然后,如何在我的程序中调用这个DLL的过程
http://fenglin.xland.cn
------------------------
mySC.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
mySC.Host = "smtp.from.com";//指定SMTP服务器
mySC.Credentials = new System.Net.NetworkCredential("myAccount","myPassword");//用户名和密码MailMessage myMM = new MailMessage("[email protected]","[email protected]");
myMM.Subject = title;//主题
myMM.Body = content;//内容
myMM.BodyEncoding = System.Text.Encoding.UTF8;//正文编码
myMM.IsBodyHtml = true;//设置为HTML格式
myMM.Priority = MailPriority.High;//优先级
try
{
mySC.Send(myMM);//发送邮件
}
catch (Exception error)
{
using (StreamWriter sw = new StreamWriter(logPath, true, System.Text.Encoding.UTF8))
{
//写入错误日志
sw.WriteLine(error.ToString());
sw.Close();
}
}
mySC.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
mySC.Host = "smtp.from.com";//指定SMTP服务器
mySC.Credentials = new System.Net.NetworkCredential("myAccount","myPassword");//用户名和密码MailMessage myMM = new MailMessage("[email protected]","[email protected]");
myMM.Subject = title;//主题
myMM.Body = content;//内容
myMM.BodyEncoding = System.Text.Encoding.UTF8;//正文编码
myMM.IsBodyHtml = true;//设置为HTML格式
myMM.Priority = MailPriority.High;//优先级
try
{
mySC.Send(myMM);//发送邮件
}
catch (Exception error)
{
using (StreamWriter sw = new StreamWriter(logPath, true, System.Text.Encoding.UTF8))
{
//写入错误日志
sw.WriteLine(error.ToString());
sw.Close();
}
}
string UserPassword = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strUserPsw, "MD5");//md5加密
SqlServerDataBase obj = new SqlServerDataBase();
obj.Insert("insert into asUserInfo (UserName,UserPassword,Question,Answer,CreateTime) values('" + UserName.Text.Trim() + "','" + UserPassword + "','" + Question.Text.Trim() + "','" + Answer.Text.Trim() + "','" + DateTime.Now.ToString() + "' )", null);
MailMessage msg = new MailMessage();
//发送方地址(如[email protected])
msg.From = "[email protected]";
//接收方地址(如[email protected])
msg.To = "[email protected]";
//正文内容类型
msg.BodyFormat = MailFormat.Html;
//正文内容编码
msg.BodyEncoding = System.Text.Encoding.Default;
//主题
msg.Subject = "您好";
//内容
msg.Body = "<html><head><META content=zh-cn http-equiv=Content-Language><meta http-equiv='Content-Type' content='text/html; charset=gb2312'><style type=text/css>A:link { FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #000000}A:visited {FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #666666}A:hover {COLOR: #ff6600; FONT-SIZE: 9pt; TEXT-DECORATION: underline}BODY {FONT-SIZE: 9pt} --></style></head><body><font color=red>用户名:" + UserName.Text.Trim() + "</font><br><font color=green>密码:" + strUserPsw.ToString() + "</font><br><b>验证地址:</b><a href='http://192.168.1.98/AllFiles/Member/CheckFromEmail.aspx?UserName=" + UserName.Text.Trim() + "'target=_blank>http://192.168.1.98/AllFiles/Member/CheckFromEmail.aspx?UserName=" + UserName.Text.Trim() + "</a>。如果您不能点击链接进行跳转,请把这个地址粘贴到浏览器的地址栏直接访问。<br><font color=red>此邮件不必回复,谢谢。</font></body></html>";
//设置为需要用户验证
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//设置验证用户名
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "zdyguilong");
//设置验证密码
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "123456");
//邮件服务器地址(如smtp.163.com)
SmtpMail.SmtpServer = "smtp.163.com";
//发送
SmtpMail.Send(msg);
//Response.Write("<script language='javascript'>alert('注册成功');window.location='../default.aspx'</script>");
Response.Redirect("../default.aspx");
{
try
{
EmailInfo emailInfo = EmailInfoManager.GetEmailInfo(); if (emailInfo != null && emailInfo.Recipients.Count > 0)
{
MailAddress from = new MailAddress(emailInfo.Sender);
MailAddress to = new MailAddress(emailInfo.Recipients[0]);
MailMessage mail = new MailMessage(from, to);
mail.Body = body;
mail.Subject = "Important Message"; if (emailInfo.Recipients.Count > 1)
{
for (int i = 1; i < emailInfo.Recipients.Count; i++)
{
mail.CC.Add(new MailAddress(emailInfo.Recipients[i]));
}
} SmtpClient client = new SmtpClient(emailInfo.SmtpServer); client.Send(mail);
}
}
catch
{
throw new Exception("Send mail error");
}
}其中EmailInfo为mail实体类