繁体   English   中英

VB.net-使用smtpclient发送电子邮件时出错

[英]VB.net - Error When Sending email using smtpclient

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

看起来您的MailTo1中包含无效的电子邮件地址。 也许尝试删除逗号后的空格。

例如email_add = email_add +“,”

这是使用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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM