我希望其他用户使用我的Visual Studio制作的应用程序向我发送电子邮件。 [英] i want other user send me email using my application that made by Visual studio.

查看:113
本文介绍了我希望其他用户使用我的Visual Studio制作的应用程序向我发送电子邮件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调试时出现此错误..



System.dll中出现未处理的System.FormatException异常例外



附加信息:指定的字符串不是电子邮件地址所需的格式。



这是我的代码..

I get this error when debug..

An unhandled exception of type 'System.FormatException' occurred in System.dll

Additional information: The specified string is not in the form required for an e-mail address.

And this is my code..

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim smtpServer As New SmtpClient()
        Dim mail As New MailMessage()
        smtpServer.Credentials = New Net.NetworkCredential(TextBox15.Text, TextBox16.Text)
        smtpServer.Port = 587
        smtpServer.Host = "smtp.gmail.com"
        smtpServer.EnableSsl = True
        mail = New MailMessage()
        mail.From = New MailAddress(TextBox18.Text)
        mail.To.Add(TextBox17.Text)
        mail.Subject = TextBox19.Text
        mail.Body = TextBox20.Text
        smtpServer.Send(mail)
        MsgBox("Mail Sent!", MsgBoxStyle.OkOnly, "Sent")
    End Sub
End Class

推荐答案

您可以查看此链接,了解如何验证电子邮件地址。

如何:验证字符串是否为有效的电子邮件格式 [ ^ ]



TextBox17.Text TextBox18.Text上使用此



就像说明一样,使用变量的描述性名称是个好主意。

默认名称会让你以后感到困惑。
You can check this link out for how to validate an email address.
How to: Verify that Strings Are in Valid Email Format[^]

Use this on TextBox17.Text and TextBox18.Text

And just as a note, it is a good idea to use descriptive names of your variables.
The default names will make you confused later on.


这篇关于我希望其他用户使用我的Visual Studio制作的应用程序向我发送电子邮件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆