我想知道如何从我的电脑发送emai我没有任何服务器来测试我的代码,我想可能是我可以使用谷歌/雅虎smtp,但我不知道如何使用them.and我想知道如果我使用谷歌/雅虎smtp然后我可以发送电子邮件给每一个? 我不知道我究竟应该放什么 sc.Credentials = new NetworkCredential(username,password); 我把我的管理员用户名和密码,我定义它在我的web.config文件中的证书标签 这是我的代码:如何使用Gmail /雅虎的smtp
protected void SendMail(string ma,DataRow dataRow)
{
try
{
string from = "[email protected]";
string subject = "forgotten password";
string body = "name: " + dataRow["user_name"].ToString() + "<br/>" + "familly : " + dataRow["user_familly"].ToString() + "<br/>" + "password : " + dataRow["user_password"].ToString();
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(from, ma, subject, body);
mail.IsBodyHtml = false;
System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient();
sc.Port = 587;
sc.Host = "smtp.mail.yahoo.com";// "smtp.gmail.com";
sc.EnableSsl = false;
sc.Send(mail);
Label1.ForeColor = System.Drawing.Color.Blue;
Label1.Text = "your password sent";
}
catch (Exception e)
{
Label1.Text = e.ToString();
}
}
http://stackoverflow.com/questions/704636/sending-email-through- gmail-smtp-server-with-c-sharp – adt 2013-02-11 09:21:58