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
指定的字符串不是电子邮件所需的格式 地址。
这是它显示的错误。在此之前它完美地工作。有人帮忙吗?
这里的全功能代码
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 = "ts_admin@astigp.com"
'Dim MailTo1 As String = "tancheekeong@astigp.com, keesoonwei@astigp.com, karentan@astigp.com"
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
答案 0 :(得分:1)
看起来您的MailTo1中包含无效的电子邮件地址。 也许尝试删除逗号后的空格。
e.g。 email_add = email_add +&#34;,&#34;
答案 1 :(得分:0)
这是使用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