Potwierdzenie Mail

0

Część probuję w asp.net mvc zrobić potwierdzenie maila po zarejestrowaniu sie na stronie. Niestety ciągle dostaję poniższy komunikat:
System.Net.Mail.SmtpException: 'Serwer SMTP wymaga bezpiecznego połączenia lub nie uwierzytelniono klienta. Response server: 5.5.1 Authentication Required. Learn more at'

 public class EmailService : IIdentityMessageService
    {
        public Task SendAsync(IdentityMessage message)
        {
            // Plug in your email service here to send an email.
            //return Task.FromResult(0);
            return Task.Factory.StartNew(() =>
            {
                sendMail(message);
            });
        }

        void sendMail(IdentityMessage message)
        {
                #region formatter
                string text = string.Format("Please click on this link to {0}: {1}", message.Subject, message.Body);
                string html = "Please confirm your account by clicking this link: <a href=\"" + message.Body + "\">link</a><br/>";

                html += HttpUtility.HtmlEncode(@"Or click on the copy the following link on the browser:" + message.Body);
                #endregion

                MailMessage msg = new MailMessage();
                msg.From = new MailAddress(ConfigurationManager.AppSettings["Email"].ToString());
                msg.To.Add(new MailAddress(message.Destination));
                msg.Subject = message.Subject;
                msg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(text, null, MediaTypeNames.Text.Plain));
                msg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html));

                SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", Convert.ToInt32(587));
                System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["Email"].ToString(), ConfigurationManager.AppSettings["Password"].ToString());
                smtpClient.Credentials = credentials;
                smtpClient.EnableSsl = true;
                //smtpClient.UseDefaultCredentials = true;
                //smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtpClient.Send(msg);

        }
    }

Plik Web.config:
  <appSettings>
    <add key="Email" value="[email protected]"/>
    <add key="Password" value=""/>
  </appSettings>

Próbowałem każda solucję z poniższego linku zrobić, niestety w dalszym ciągu nie działa.
https://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not

Czy ktoś ma jakiś pomysł, jak mogę rozwiązać powyższy problem?

1

Mam nadzieje, że Ci to coś pomoże. (Jbc, to sprawdzałem teraz i działa (na dole screen z gmaila))

static List<string> ListOfEmails = new List<string>(); 

private async void button2_Click(object sender, EventArgs e)
{
	await Task.Run
	(
		 () => SendEmail()
	);
}

private void SendEmail()
{
	var client = new SmtpClient(Email_Host.Text, Convert.ToInt32(Email_Port.Text))
	{
		Credentials = new NetworkCredential(Email_Login.Text, Email_Password.Text),
		EnableSsl = true
	};

	this.Invoke(new Action(async delegate ()
	{
		foreach (string email in ListOfEmails)
		{
			client.Send(Email_Login.Text, email, Email_Subject.Text,
			string.Format(Email_Message.Text, email.Split('@')[0], DateTime.Now.ToString()));
			await Task.Delay(1000);
		}
	}));
}

1.PNG
2.PNG

PS: dodam, że zbytnio nie ogarniam actionow/delegatow/taskow :P

1 użytkowników online, w tym zalogowanych: 0, gości: 1