Principale utente con più risposte
Inviare una posta elettronica con un codice di Google

Domanda
-
Ho sempre inviato la posta email attraverso una mia applicazione compilato con Visual Studio 2019. Il codice è quello sotto riportato, ma all'improvviso mi compare questo messaggio : il tipo di crittografia richiesta non è supportata da KDC il quale non mi permette d'inviare la posta. Che è successo che prima non si era mai presentato? Mi è caduta una tegola in testa !!!!!!
smtpServer.Credentials = New Net.NetworkCredential(CREDBUYER, PASSWORDSISTEMA)
smtpServer.Port = 587
smtpServer.Host = "smtp.gmail.com"
smtpServer.EnableSsl = True
mail = New MailMessage()
mail.From = New MailAddress(CREDBUYER)
mail.To.Add(EmailA)mail.CC.Add(EmailPerConoscienza)
mail.Subject = OggettoEmail
mail.Body = TestoEmailsmtpServer.Send(mail)
Pantaleo
Risposte
-
Ciao Pantaleo,
Controlla se il looping creato non si riferisce al email con DBNull.value, se questo non è il caso, puoi riferirti alla documentazione per KDC
Di sotto un esemplario syntax che ho a disposizione e lavora:
Imports System.Net.Mail 'Namespace per spedizione email Public Class Form1 'Whatever class your doing this from... 'I tested with a button click event... Private Sub btnSendEmail_Click(sender As Object, e As EventArgs) Handles btnSendEmail.Click Dim dtEmails As New DataTable Dim strEmails() As String = {"testing@yahoo.com", "testing@gmail.com"} Dim strBuilder As New System.Text.StringBuilder 'This was only for my testing... dtEmails.Columns.Add("EmailAddress") For Each Str As String In strEmails dtEmails.Rows.Add(Str) Next 'Loop through our returned datatable and send the emails...' If dtEmails.Rows.Count > 0 Then strBuilder.AppendLine("Emails Confirmation") strBuilder.AppendLine(" ") For i As Integer = 0 To dtEmails.Rows.Count - 1 'Whatever your datatbale is called' Try Dim newMail As New Mail 'Use our new mail class to set our properties for the email' newMail.MailMessageTo = dtEmails.Rows(i).Item("EmailAddress") 'What your email address column name is in the data table' newMail.MailSubject = "Just a Test email!" newMail.MailMessage = "Did you get this email, please let me know!" If Mail.SendMail(newMail) Then strBuilder.AppendLine("SENT - " & dtEmails.Rows(i).Item("EmailAddress").ToString.ToUpper) Else strBuilder.AppendLine("FAILED - " & dtEmails.Rows(i).Item("EmailAddress").ToString.ToUpper) End If Catch ex As Exception Continue For End Try Next End If If strBuilder.Length > 0 Then MessageBox.Show(strBuilder.ToString()) End If End Sub End Class 'You can put this class at the bottom of your class your using...This handles the emails... Public Class Mail Public Property MailMessageTo As String Public Property MailMessage As String Public Property MailSubject As String 'This will send your mail... Public Shared Function SendMail(ByVal oMail As Mail) As Boolean Dim Smtp_Server As New SmtpClient Dim e_mail As New MailMessage() Try Smtp_Server.UseDefaultCredentials = False Smtp_Server.Credentials = New Net.NetworkCredential("EMAIL", "PASSWORD") Smtp_Server.Port = 587 Smtp_Server.EnableSsl = True Smtp_Server.Host = "smtp.gmail.com" e_mail = New MailMessage() e_mail.From = New MailAddress("EMAIL") 'Whatever you want here' e_mail.To.Add(oMail.MailMessageTo) e_mail.Subject = oMail.MailSubject e_mail.IsBodyHtml = False e_mail.Body = oMail.MailMessage Smtp_Server.Send(e_mail) Return True Catch error_t As Exception Return False Finally Smtp_Server = Nothing e_mail = Nothing End Try End Function End Class
Microsoft offre questo servizio gratuitamente, per aiutare gli utenti e aumentare il database dei prodotti e delle tecnologie. Il contenuto fornito “as is“ non comporta alcuna responsabilità da parte dell’azienda.
- Contrassegnato come risposta aguanagana1 mercoledì 23 novembre 2022 17:46