我想发送邮件(gmail到gmail) --这是c#的代码:
我现在很容易,而且存在更多的图托。我测试所有的tuto发送邮件,但总是同样的问题。
using System;
using System.Net.Mail;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
namespace VerificationBlockage
{
class EnvoyerMail
{
public void sendEmail()
{
// Mail message construction
MailMessage mm = new MailMessage("halloula.briki@gmail.com", "halloula.briki@mail.com");
// content
mm.Subject = "testing message";
mm.Body = "hello... from .net c# mailmessage";
mm.CC.Add("mejdi68@mail.com");
// mm.CC.Add("copycc2@mail.com");
// mm.Bcc.Add("copybcc@mail.com");
// some attachments
//mm.Attachments.Add(new Attachment("c:\\filename.txt"));
// Sending message
SmtpClient sc = new SmtpClient("smtp.gmail.com", 587);
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
// ...
// our account credentials
sc.Credentials = new NetworkCredential("halloula.briki@gmail.com", "&******&");
sc.EnableSsl = true;
// Catching result
try
{
sc.Send(mm);
MessageBox.Show("Message sent");
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
}
}我不知道有什么问题。我换了25,587,465港口。误差为le serveur en电荷les connexions sécurisées。
英文翻译:
服务器不支持安全连接。
发布于 2015-06-03 14:44:55
这表明您使用的服务器不支持SSL连接。
移除线
sc.EnableSsl = true;或改为:
sc.EnableSsl = false;不过,我相当肯定Gmail会这么做。试试这个:
public string SendGmailMessage(string toAddress, string fromAddress, string ccAddress, string subject, string body)
{
MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string msg = string.Empty;
try
{
MailAddress emailFrom = new MailAddress(fromAddress);
message.From = emailFrom;
message.To.Add(toAddress);
if (!string.IsNullOrEmpty(ccAddress))
{
message.CC.Add(ccAddress);
}
message.Subject = subject;
message.IsBodyHtml = true;
message.Body = body;
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 587;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = true; //Add this line
smtpClient.Credentials = new System.Net.NetworkCredential("GMAILUSERNAME", "GMAILPASSWORD");
smtpClient.Send(message);
msg = "Message Sent";
}
catch (Exception ex)
{
msg = ex.Message;
}
return msg;
}发布于 2015-06-03 14:54:37
这可能取决于连接到该端口(服务器端)的gmail服务。我看到了一些使用SSL连接到端口465的例子
我希望这能帮到你。
发布于 2015-06-03 15:28:39
这很可能是防火墙的问题。你查过了吗?在cmd提示符下,检查以下内容:
Telnet smtp.gmail.com 587
如果您没有得到一个有效的响应返回,有东西阻塞了该端口。
https://stackoverflow.com/questions/30623299
复制相似问题