简体   繁体   English

使用Gmail Smtp发送电子邮件,但不发送吗?

[英]Sending an Email with Gmail Smtp, but it doesnt send?

I am trying to send an email through code using gmail smtp however, it just wont send to the user. 我正在尝试通过使用gmail smtp的代码发送电子邮件,但是,它不会发送给用户。 The sent emails are indeed in the "sent email" folder and in the correct format. 已发送的电子邮件确实位于“已发送的电子邮件”文件夹中,并且格式正确。 I tried sending the email regularly to see if its perhaps the email address but everything sent fine. 我尝试定期发送电子邮件,以查看是否可能是电子邮件地址,但一切都发送正常。 I am not sure why this isnt working... Any ideas would be appreciated. 我不确定为什么这行不通...任何想法将不胜感激。

The code: 编码:

//this will build the email and send it 
        public void sendEmail()
        {
          var client = new SmtpClient("smtp.gmail.com", 587)
            {
                Credentials = new NetworkCredential(GlobalVars.strFromEmail, "pass"),
                EnableSsl = true
            };
            client.Send(GlobalVars.strFromEmail,GlobalVars.strEmailAddress, "test", "testbody");
            Console.WriteLine("Sent");
            Console.ReadLine();
        }  

FIXED: Nevermind everyone, it was just taking an extremly long time to send (like an hour)... 修正:没关系,每个人都花了很长时间才能发送(例如一个小时)...

您最好使用try catch块来查看列出了哪种错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM