如何允许程序访问 Google 帐户?

时间:2021-07-15 03:43:18

标签: email smtp

SMTP 应用程序是我公司项目的最新功能。该程序记录皮肤数据并将其记录在图表中。有人可能想要输入皮肤数据报告并将消息和图表发送给客户。

这是我的代码。

private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage message = new MailMessage();
                SmtpClient smtp = new SmtpClient();
                message.From = new MailAddress(textBoxUserEmail.Text);
                message.To.Add(new MailAddress(textBoxCustomerEmail.Text));
                message.Subject = "Test";
                message.IsBodyHtml = true; 
                message.Body = textBoxMessage.Text;
                smtp.Port = 587;
                smtp.Host = "smtp.gmail.com"; 
                smtp.EnableSsl = true;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new NetworkCredential(textBoxUserEmail.Text, textBoxPassword.Text);
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

                smtp.Send(message);
                this.Close();
            }catch (Exception sendingEx)
            {
                ErrorForm error = new ErrorForm();
                error.label3.Text = sendingEx.Message+". Check your network connection or credentials, and try again.";
                error.ShowDialog();
                this.Close();
            }
        }

我通过向我自己的电子邮件地址发送一条简单消息来测试该程序,然后我收到此错误消息:“SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1 身份验证必需的。”。我还收到一封电子邮件,说 Google 阻止了可疑登录,也就是说,我的在线举报功能已被 Google 阻止!

如何让 Google 信任我的应用?

0 个答案:

没有答案