大虾们,谁会email啊?

duanlongk 2008-11-11 12:37:30
大侠们,谁能给我一个能成功发送的email的代码啊,现在好多的都用不起,要带验证的。谢谢哈
web的,winform的请标注哈,我现在都有点弄混了
...全文
672 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
Adechen 2008-11-11
  • 打赏
  • 举报
回复
说得很清楚了,帮顶了
  • 打赏
  • 举报
回复
Private Sub sendmail(ByVal Subject As String, ByVal from As String, ByVal SendTo As String, ByVal Message As String, Optional ByVal FileName As String = "")
Dim Mail As New MailMessage
If FileName <> "" Then
Mail.Attachments.Add(New MailAttachment(FileName))

End If

With Mail
.From = from
.To = SendTo
.Subject = Subject
.Body = Message
.Priority = MailPriority.High
.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "25") 'sendmail server port
.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") ' Do you want to verify
.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "xxxxxxx") 'send mail password
.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username") 'Mail User name.
End With

'SmtpMail.SmtpServer.Insert(0, "127.0.0.1")
SmtpMail.SmtpServer = "smtp.126.com"

Try
SmtpMail.Send(Mail)
Catch ex As Exception
MessageBox.Show(ex.ToString() & "--" & ex.Message)
Return
End Try
MessageBox.Show("Send Successfully")
End Sub


那一定是你 password and username 么有填写对!
zero8500 2008-11-11
  • 打赏
  • 举报
回复
网上很多了吧
lovehongyun 2008-11-11
  • 打赏
  • 举报
回复
 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);
gengwanshanreally 2008-11-11
  • 打赏
  • 举报
回复
顶一下!
w161134025 2008-11-11
  • 打赏
  • 举报
回复
using System.Net;
using System.Net.Mail;


public bool ShowPost()//gmail的发送方法
{
string from = "4757456732@qq.com";
string pwd = "7420861467wang";
string to = TxtTo.Text.Trim();
MailMessage mail = new MailMessage(from,to);
mail.Subject = TxtHead.Text;
mail.SubjectEncoding = System.Text.Encoding.GetEncoding("gb2312");
mail.Body = TxtBody.Text;
mail.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");
mail.IsBodyHtml = true;
string server = "";
int port = 25;
if (from.IndexOf("@gpres")!=-1 || from.IndexOf("@gmail")!=-1)
{
port = 587;
server = "smtp.gmail.com";
}
else
{
port = 25;
string temp;
temp=from.Substring(from.LastIndexOf('@')+1);
server = "smtp." + temp;
}
SmtpClient sc = new SmtpClient(server, port);
if (port!=25)
{
sc.EnableSsl = true;
}
sc.Credentials = new NetworkCredential(from, pwd);


try
{
sc.Send(mail);
mail.Dispose();
return true;
}
catch(Exception ex)
{
//System.Web.HttpContext.Current.Response.Write(e.Message);
mail.Dispose();
return false;
}

}
w161134025 2008-11-11
  • 打赏
  • 举报
回复
using System.Net;
using System.Net.Mail;


public bool ShowPost()//gmail的发送方法
{
string from = "4757456732@qq.com";
string pwd = "7420861467wang";
string to = TxtTo.Text.Trim();
MailMessage mail = new MailMessage(from,to);
mail.Subject = TxtHead.Text;
mail.SubjectEncoding = System.Text.Encoding.GetEncoding("gb2312");
mail.Body = TxtBody.Text;
mail.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");
mail.IsBodyHtml = true;
string server = "";
int port = 25;
if (from.IndexOf("@gpres")!=-1 || from.IndexOf("@gmail")!=-1)
{
port = 587;
server = "smtp.gmail.com";
}
else
{
port = 25;
string temp;
temp=from.Substring(from.LastIndexOf('@')+1);
server = "smtp." + temp;
}
SmtpClient sc = new SmtpClient(server, port);
if (port!=25)
{
sc.EnableSsl = true;
}
sc.Credentials = new NetworkCredential(from, pwd);


try
{
sc.Send(mail);
mail.Dispose();
return true;
}
catch(Exception ex)
{
//System.Web.HttpContext.Current.Response.Write(e.Message);
mail.Dispose();
return false;
}

}
duanlongk 2008-11-11
  • 打赏
  • 举报
回复
大虾可以提供一个可以用的126邮箱么,我的126邮箱是06年11月后申请的都没法用,
庚武讲堂 2008-11-11
  • 打赏
  • 举报
回复
你的是不是QQ邮箱啊,请查看你的邮箱是否开通pop3/smtp服务,QQ邮箱要自己去开通的吧,可以用126,163的试一下,以前我测试也都是163的邮箱.发送邮件在.net中是非常简单的,一般程序不会出什么问题。
duanlongk 2008-11-11
  • 打赏
  • 举报
回复
大虾 ,出现异常,说是邮箱不可用,可我的邮箱都能用的啊,麻烦大虾指点
duanlongk 2008-11-11
  • 打赏
  • 举报
回复
大虾 ,出现异常,说是邮箱不可用,可我的邮箱都能用的啊,麻烦大虾指点
melon23 2008-11-11
  • 打赏
  • 举报
回复
<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;
}
}
evjen 2008-11-11
  • 打赏
  • 举报
回复
yufeizhan 2008-11-11
  • 打赏
  • 举报
回复

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;

}
}

}



我正用的。
private static string这里的三行参数自己配置。
zlb789 2008-11-11
  • 打赏
  • 举报
回复
我也碰到过这样的问题

现在注册都被限制了
mengxj85 2008-11-11
  • 打赏
  • 举报
回复
上面的很多方法挺好的,顶
pdsnet 2008-11-11
  • 打赏
  • 举报
回复
 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
{


}

刚弄好的 ..sina的要自己设置下 开通smtp 网易据说是 06年10月前的能用.
ustbwuyi 2008-11-11
  • 打赏
  • 举报
回复
用不起是啥意思

http://www.cnblogs.com/ustbwuyi第一篇文章

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧