Reputation: 5
Dim MailBody1 As String = vbCrLf & "A new carrier tape (Part Number: " & code & ") has been added into the system. Please verify and buy-off the specs in the MRP system. " & vbCrLf & vbCrLf & "MRP System: " & tsURL & vbCrLf & "Module: Manufacturing --> First Article --> QA"
Dim MailClient1 = New SmtpClient("localhost")
MailClient1.send(MailFrom1, MailTo1, MailSubject1, MailBody1)
'Catch ex As Exception
'End Try
The specified string is not in the form required for an e-mail address.
this is the error it shows. Before that it work perfectly. Anyone help?
Full function code here
Public Sub send_email(ByVal code)
Dim tsURL As String = "http://orion/one/"
Dim n As Integer
Dim email_add As String
conn1("SELECT * FROM hr_employee WHERE emp_position IN ('QA ENGINEER', 'SR. QA ENGINEER') AND status = 'employed'", "email_add")
If ds.Tables("email_add").Rows.Count > 0 Then
For n = 0 To ds.Tables("email_add").Rows.Count - 1
dr = ds.Tables("email_add").Rows(n)
If n <> ds.Tables("email_add").Rows.Count - 1 Then
email_add = email_add + dr("email")
email_add = email_add + ", "
Else
email_add = email_add + dr("email")
End If
Next
End If
'Try
Dim MailFrom1 As String = "[email protected]"
'Dim MailTo1 As String = "[email protected], [email protected], [email protected]"
Dim MailTo1 As String = email_add
Dim MailSubject1 As String = "New Carrier Tape : " & code
Dim MailBody1 As String = vbCrLf & "A new carrier tape (Part Number: " & code & ") has been added into the system. Please verify and buy-off the specs in the MRP system. " & vbCrLf & vbCrLf & "MRP System: " & tsURL & vbCrLf & "Module: Manufacturing --> First Article --> QA"
Dim MailClient1 = New SmtpClient("localhost")
MailClient1.send(MailFrom1, MailTo1, MailSubject1, MailBody1)
'Catch ex As Exception
'End Try
Upvotes: 0
Views: 1744
Reputation: 486
Looks like your MailTo1 has invalid email address in it. Maybe try to remove the space after the comma.
e.g. email_add = email_add + ","
Upvotes: 1
Reputation: 1326
This is the simplest method of sending a mail using SmtpClient
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
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(txtemail.Text)
e_mail.To.Add(txtemail.Text)
e_mail.Subject = "Email Sending"
e_mail.IsBodyHtml = False
e_mail.Body = txtMessage.Text
Smtp_Server.Send(e_mail)
MsgBox("Mail Sent")
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
Upvotes: 0