尝试使用Google smtp通过电子邮件客户端程序发送电子邮件时出现AuthenticationException

时间:2019-05-21 05:17:34

标签: c# exception smtp

我一直在尝试学习如何在C#中使用Net.Mail软件包,并从getgo中遇到了麻烦。每当我尝试测试程序时,都会得到相同的AuthenticationException。

我检查了SO上的其他帖子,然后有人提到他们的防病毒软件正在替换证书,因此我尝试将其关闭都无济于事,并尝试通过禁用SSL身份验证来解决该问题,但这只是改变了我的例外,因为显然Google赢得了不会接受通过端口587进行的不安全传输。我确实更愿意使用SSL身份验证。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Mail;
using System.Net;

namespace EmailSender
{
    public partial class Mailer : Form
    {
        public Mailer()
        {
            InitializeComponent();
        }

        private void Mailer_Load(object sender, EventArgs e)
        {

        }

        private void btn_send_Click(object sender, EventArgs e)
        {
            MailMessage message = new MailMessage();
            message.From = new MailAddress(txt_email.Text);
            message.Subject = txt_subject.Text;
            message.Body = txt_body.Text;
            foreach (string s in txt_recipients.Text.Split(';'))
            {
                message.To.Add(s);
            }
            SmtpClient client = new SmtpClient();
            client.Credentials = new NetworkCredential(txt_email.Text, txt_password.Text);
            client.Host = "smtp-gmail.com";
            client.Port = 587;
            client.EnableSsl = true;
            client.Send(message);
        }
    }
}

这是我的堆栈跟踪

    System.dll!System.Net.Mail.SmtpClient.Send(System.Net.Mail.MailMessage message) Unknown
>   EmailSender.exe!EmailSender.Mailer.btn_send_Click(object sender, System.EventArgs e) Line 42    C#
    System.Windows.Forms.dll!System.Windows.Forms.Control.OnClick(System.EventArgs e)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Button.OnClick(System.EventArgs e)    Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Button.OnMouseUp(System.Windows.Forms.MouseEventArgs mevent)  Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.ButtonBase.WndProc(ref System.Windows.Forms.Message m)    Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Button.WndProc(ref System.Windows.Forms.Message m)    Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam)  Unknown
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData)  Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context)    Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm)   Unknown
    EmailSender.exe!EmailSender.Program.Main() Line 19  C#

0 个答案:

没有答案