Resolved Send email function error

luckydead

New member
Joined
Feb 3, 2022
Messages
4
Programming Experience
1-3
I have issue with my code,
what i receive as error is :
System.ArgumentException: 'Argument 'Prompt' cannot be converted to type 'String'.'
and it's always shows
Catch ex As System.Exception
MsgBox(ex, MsgBoxStyle.Critical)
End Try

i have try to add in my google account insecure app is turned on, but still cannot send the email.
VB.NET:
 Private Sub SendEmailGmail()
        Try
            Dim SMTP_Server As New SmtpClient
            Dim Mail As New MailMessage
            SMTP_Server.UseDefaultCredentials = False
            SMTP_Server.Credentials = New Net.NetworkCredential(txtUserAcc.Text, txtUserPass.Text)
            SMTP_Server.Host = "smtp.gmail.com"
            SMTP_Server.Port = 587 'Check Port
            SMTP_Server.EnableSsl = True
            Mail = New MailMessage()
            Mail.From = New MailAddress(txtFrom.Text)
            Mail.To.Add(txtTo.Text)
            Mail.CC.Add(txtCC.Text)
            Mail.IsBodyHtml = True
            Mail.Priority = MailPriority.Normal
            Mail.BodyEncoding = System.Text.Encoding.UTF8
            Mail.SubjectEncoding = System.Text.Encoding.UTF8
            Mail.Subject = txtBody.Text
            Mail.Body = txtBody.Text
            If Guna2DataGridView1.Rows.Count > 0 Then
                For Each row As DataGridViewRow In Guna2DataGridView1.Rows
                    If row.Cells("Path").Value IsNot Nothing Then
                        Dim MsgAttach As New Attachment(row.Cells("Path").Value)
                        Mail.Attachments.Add(MsgAttach)
                    End If
                Next
            End If
            SMTP_Server.Send(Mail)
            MsgBox("Email was Sended", MsgBoxStyle.Information)
        Catch ex As System.Exception
            MsgBox(ex, MsgBoxStyle.Critical)
        End Try
    End Sub
 
as i go more in details to search i find out what brake has,
the problem comes from the preferences so i find it out the issue
using
MessageBox.Show(ex.ToString) was better option to find the issue
 

Latest posts

Back
Top