当我尝试使用VB.Net或C#用Gmail发送电子邮件时,我一直收到以下消息:发送电子邮件失败-试图以访问权限禁止的方式访问套接字-无法访问远程服务器。我已经尝试使用了几个Gmail帐户,包括以前有效的VB.Net代码,如下所示:
Message = New MailMessage(Sender, Recipient, Subject, MessageBody)
SMTPServer = New SmtpClient("smtp.gmail.com", 587)'Port 465 fails as well
SMTPServer.EnableSsl = True
SMTPServer.Credentials = New NetworkCredential("Username@gmail.com", "password")
SMTPServer.Send(Message)
(我知道web.config可以用在上面的很多方面)。
显然,Gmail一定是改变了一些设置或类似的东西?
发布于 2012-01-29 13:08:32
它是McAfee防病毒软件,可以阻止电子邮件的发送。谢谢你的帮助,很抱歉浪费了大家的时间。
发布于 2012-01-28 11:12:42
这段代码对我来说工作得很好:
try
{
MailMessage mail = new MailMessage(); //using System.Net.Mail namespace
mail.To.Add("xyz@yahoo.com"); //Enter reciever's email address
mail.From = new MailAddress("abc@gmail.com"); //Enter sender's email address
mail.Subject = "Testing mail...";
mail.Body = @"Lets-code ! Lets-code to make it simpler";
mail.IsBodyHtml = true; //Body of mail supports html tags
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "pwd");
// Your gmail username and password
smtp.EnableSsl = true; //Gmail uses a encrypted connection
smtp.Send(mail);
Response.Write("Mail Sent Successfully");
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
如果这不起作用,可以在另一台机器上尝试。Windows7有自己的防火墙。一定要检查一下。
发布于 2012-01-28 10:52:02
我不知道如何评论,所以:我想你忘了港口和一些东西。看看这是否有帮助:
Imports System.Net.Mail
Protected Sub btnSendEmail_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim mail As MailMessage = New MailMessage()
mail.To.Add("receiversmail@gmail.com")
mail.From = New MailAddress("yourmail@gmail.com")
mail.Subject = "Email using Gmail"
String Body = "Sending mail using Gmail's SMTP"
mail.Body = Body
mail.IsBodyHtml = True
Dim smtp As SmtpClient = New SmtpClient()
smtp.Host = "smtp.gmail.com"
smtp.Credentials = New System.Net.NetworkCredential
("yourmail@gmail.com","password")
smtp.EnableSsl = True
smtp.Port = 587
smtp.EnableSsl = true
smtp.Send(mail)
End Sub
尝试此编辑
https://stackoverflow.com/questions/9044515
复制相似问题