简体   繁体   English

如何在vb.net中的文本框中检查特定的单词/短语

[英]how to check for specific words/phrase in a textbox in vb.net

I need to check for specific words so that the program will know what smtp client will be used. 我需要检查特定的单词,以便程序知道将使用什么smtp客户端。 For example. 例如。 If the from textbox will have @yahoo.com on it then the program will make use of the smtp for yahoo. 如果发件人文本框上有@ yahoo.com,则该程序将使用smtp替代yahoo。 Or if you know of any way on how to do just the same but with other idea. 或者,如果您知道如何执行相同的操作但又有了其他想法。

    If yourTextBox.Text.Contains("@yahoo.com") Then
        'make use of smtp for yahoo
    End If

And if you have more complicated phrases/rules to find, make yourself comfortable with regular expressions. 并且,如果您要查找更复杂的短语/规则,请使自己适应正则表达式。

You can't make this work in the general case, just a server name isn't enough. 在一般情况下,仅靠服务器名称是不够的,因此您无法使其正常工作。 The days that SMTP servers accepted an email message without any authentication are long gone. SMTP服务器接受未经任何身份验证的电子邮件的日子已经一去不复返了。 You will need to use the SmtpClient.Credentials property to proof to the server that the user is legit. 您将需要使用SmtpClient.Credentials属性来向服务器证明用户是合法的。

Perhaps more to the point, you only need one SMTP server. 也许更重要的是,您只需要一个SMTP服务器。 As long as the user can authenticate, s/he can use the server to distribute email to any recipient. 只要用户可以进行身份​​验证,他/她就可以使用服务器将电子邮件分发给任何收件人。 Add a configuration feature to your app so the user can provide the server address, port number and required credentials. 添加配置功能,以您的应用程序,使用户可以提供服务器地址,端口号和所需的凭证。

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

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