请问如何将表单内填写的内容在点击按钮后提交到指定的email信箱里?? 请给出一个简单的例子代码。另外问下,用email提交机器上必须使用outlook吗?如果没有安装outlook有办法提交表单到指定信箱吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是我发邮件的例子.楼主可以直接用.不过要用户名称空间. /// <summary> /// 发送邮件 /// </summary> /// <param name="To">收件人</param> /// <param name="From">发件人</param> /// <param name="Subject">主题</param> /// <param name="Body">内容</param> /// <param name="IsHtml">是否Html格式</param> /// <returns>返回是否发送成功</returns> private static bool SendMail(string To,string From,string Subject,string Body,bool IsHtml) { bool IsOk = false; string SmtpServer = Global.SmtpServer.ToString(); string SmtpUserName = Global.SmtpUserName.ToString(); string SmtpPassWord = Global.SmtpPassWord.ToString(); MailMessage Mail = new MailMessage(); Mail.To = To; Mail.From = From; Mail.Subject = Subject; Mail.Body = Body; Mail.BodyFormat = (IsHtml) ? MailFormat.Html:MailFormat.Text; Mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312"); if (SmtpUserName != "" && SmtpPassWord != "") { Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1"); Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",SmtpUserName); Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",SmtpPassWord); } SmtpMail.SmtpServer = "192.168.1.2";//SmtpServer; try { SmtpMail.Send(Mail); IsOk = true; } catch//(Exception e) { //记录e.Message到日志 } return IsOk; } 请试一下这个:www.goarena.net/mailonline.aspx如果发送成功,请向我索要源码! "子风"一定合你意,不用outlook!采用web表单! 当时我做项目是写的,你参考一下吧!//**************************************************************发送邮件开始 MailMessage myMail=new MailMessage(); StringBuilder MailBody=new StringBuilder(); myMail.From="[email protected]"; myMail.To=email; myMail.Subject="主题xxxxxx"; myMail.BodyFormat=MailFormat.Html; MailBody.Append("<style>A:visited { TEXT-DECORATION: none }"); MailBody.Append("A:active { TEXT-DECORATION: none }"); MailBody.Append("A:hover { TEXT-DECORATION: underline }"); MailBody.Append("A:link { text-decoration: none;}"); MailBody.Append("A:visited { text-decoration: none;}"); MailBody.Append("BODY { FONT-FAMILY: Verdana,宋体; FONT-SIZE: 9pt;}"); MailBody.Append("TD { FONT-FAMILY: Verdana,宋体; FONT-SIZE: 9pt }</style>"); MailBody.Append("<TABLE border=0 width='95%' align=center><TBODY><TR>"); MailBody.Append("<TD valign=middle align=top>"); MailBody.Append( DomainName + ",您好:<br><br>"); MailBody.Append("欢迎您使用LINYI.NET免费域名系统,我们将提供给您最好的域名转向服务!<br><br>"); MailBody.Append("下面是您的注册信息如下:<br>"); MailBody.Append("域名:<b>"+DomainName+".linyi.net</b><br>"); MailBody.Append("您的密码:"+pwd+"<br>"); MailBody.Append("注册邮箱:"+email+"<br>"); MailBody.Append("转向地址:"+url+"<br>"); MailBody.Append("网站名称:"+siteName+"<br>"); MailBody.Append("<br>现在您可以通过<a href='http://" +DomainName+ ".linyi.net' target='_blank'>http://" +DomainName+ ".linyi.net</a>或"); MailBody.Append("<a href='http://www." +DomainName+ ".linyi.net' target='_blank'>http://www." +DomainName+ ".linyi.net</a>来访问您的网站,赶快试试吧!"); MailBody.Append("<br><br>"); MailBody.Append("<center><font color=red>全方位的.NET技术资源,尽在linyi.net!欢迎您下次光临!</font></TD></TR>"); MailBody.Append( "<TR><TD align=right><a href='http://www.linyi.net' target='_blank'><img src='http://www.linyi.net/images/logo.gif' "); MailBody.Append( "border=0 alt='www.linyi.net'></a></TD></TR>"); MailBody.Append("</TBODY></TABLE><br>"); myMail.Body=MailBody.ToString(); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "[email protected]"); //SMTP 用户 myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "test");//'SMTP 密码 SmtpMail.SmtpServer = "mail.xxx.com"; //SMTP服务器 SmtpMail.Send(myMail); //************************************************************************发送邮件结束 private void btnSend_Click(object sender, System.EventArgs e) { //分别取得邮件的发信人、收信人、主题以及邮件主体等信息 string strFrom = tbFrom.Text; string strTo = tbTo.Text; string strSubject = tbSubject.Text; string strMsgText = tbMsgText.Text; try { SmtpMail.SmtpServer = "smtp.sina.com.cn"; SmtpMail.Send(strFrom,strTo,strSubject,strMsgText); //清除Label控件中的内容 tbTo.Text = ""; tbSubject.Text = ""; tbMsgText.Text = ""; lblShowMsg.Text = "发送至<b>"+strTo+"</b>邮件,发送成功"; } catch(Exception ee) { lblShowMsg.Text = "发送邮件失败:"+ee.ToString(); } }不用装outlook,只要邮件服务器可用就可以了。 截取字符串问题。。。。 xml文档放在网站app_data下安全吗? 数据库还原时的一个存储过程 .wav文件压缩成byte[]后如何形成可播放的文件 关于label的visible值 关于数据访问层sqlhelper是否都是一样? 聊天室原代码啊,急,有能帮到我的必以高分相送 问个DataGrid模板列的问题。高手请进。 请问如何在下拉菜单前面的每个条目前加个小图标啊,能不能举个例子先,先谢了:) 关于向XML中插入新数据的问题,请高手指点。 请求帮助,有关于IIS. 怎么把二维数组绑定到DropDownList?我想应该可以,但不知道怎么做.
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="To">收件人</param>
/// <param name="From">发件人</param>
/// <param name="Subject">主题</param>
/// <param name="Body">内容</param>
/// <param name="IsHtml">是否Html格式</param>
/// <returns>返回是否发送成功</returns>
private static bool SendMail(string To,string From,string Subject,string Body,bool IsHtml)
{
bool IsOk = false;
string SmtpServer = Global.SmtpServer.ToString();
string SmtpUserName = Global.SmtpUserName.ToString();
string SmtpPassWord = Global.SmtpPassWord.ToString();
MailMessage Mail = new MailMessage();
Mail.To = To;
Mail.From = From;
Mail.Subject = Subject;
Mail.Body = Body;
Mail.BodyFormat = (IsHtml) ? MailFormat.Html:MailFormat.Text;
Mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
if (SmtpUserName != "" && SmtpPassWord != "")
{
Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1");
Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",SmtpUserName);
Mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",SmtpPassWord);
}
SmtpMail.SmtpServer = "192.168.1.2";//SmtpServer;
try
{
SmtpMail.Send(Mail);
IsOk = true;
}
catch//(Exception e)
{
//记录e.Message到日志
}
return IsOk;
}
如果发送成功,请向我索要源码!
//**************************************************************发送邮件开始
MailMessage myMail=new MailMessage();
StringBuilder MailBody=new StringBuilder();
myMail.From="[email protected]";
myMail.To=email;
myMail.Subject="主题xxxxxx";
myMail.BodyFormat=MailFormat.Html; MailBody.Append("<style>A:visited { TEXT-DECORATION: none }");
MailBody.Append("A:active { TEXT-DECORATION: none }");
MailBody.Append("A:hover { TEXT-DECORATION: underline }");
MailBody.Append("A:link { text-decoration: none;}");
MailBody.Append("A:visited { text-decoration: none;}");
MailBody.Append("BODY { FONT-FAMILY: Verdana,宋体; FONT-SIZE: 9pt;}");
MailBody.Append("TD { FONT-FAMILY: Verdana,宋体; FONT-SIZE: 9pt }</style>");
MailBody.Append("<TABLE border=0 width='95%' align=center><TBODY><TR>");
MailBody.Append("<TD valign=middle align=top>");
MailBody.Append( DomainName + ",您好:<br><br>");
MailBody.Append("欢迎您使用LINYI.NET免费域名系统,我们将提供给您最好的域名转向服务!<br><br>");
MailBody.Append("下面是您的注册信息如下:<br>");
MailBody.Append("域名:<b>"+DomainName+".linyi.net</b><br>");
MailBody.Append("您的密码:"+pwd+"<br>");
MailBody.Append("注册邮箱:"+email+"<br>");
MailBody.Append("转向地址:"+url+"<br>");
MailBody.Append("网站名称:"+siteName+"<br>");
MailBody.Append("<br>现在您可以通过<a href='http://" +DomainName+ ".linyi.net' target='_blank'>http://" +DomainName+ ".linyi.net</a>或");
MailBody.Append("<a href='http://www." +DomainName+ ".linyi.net' target='_blank'>http://www." +DomainName+ ".linyi.net</a>来访问您的网站,赶快试试吧!");
MailBody.Append("<br><br>");
MailBody.Append("<center><font color=red>全方位的.NET技术资源,尽在linyi.net!欢迎您下次光临!</font></TD></TR>");
MailBody.Append( "<TR><TD align=right><a href='http://www.linyi.net' target='_blank'><img src='http://www.linyi.net/images/logo.gif' ");
MailBody.Append( "border=0 alt='www.linyi.net'></a></TD></TR>");
MailBody.Append("</TBODY></TABLE><br>"); myMail.Body=MailBody.ToString();
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "[email protected]"); //SMTP 用户
myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "test");//'SMTP 密码
SmtpMail.SmtpServer = "mail.xxx.com"; //SMTP服务器
SmtpMail.Send(myMail);
//************************************************************************发送邮件结束
{
//分别取得邮件的发信人、收信人、主题以及邮件主体等信息
string strFrom = tbFrom.Text;
string strTo = tbTo.Text;
string strSubject = tbSubject.Text;
string strMsgText = tbMsgText.Text;
try
{
SmtpMail.SmtpServer = "smtp.sina.com.cn";
SmtpMail.Send(strFrom,strTo,strSubject,strMsgText);
//清除Label控件中的内容
tbTo.Text = "";
tbSubject.Text = "";
tbMsgText.Text = "";
lblShowMsg.Text = "发送至<b>"+strTo+"</b>邮件,发送成功";
}
catch(Exception ee)
{
lblShowMsg.Text = "发送邮件失败:"+ee.ToString();
}
}
不用装outlook,只要邮件服务器可用就可以了。