我如何排序'平'的SMTP服务器,以便我可以检查帐户/密码是一个有效的? [英] How can I sort of 'ping' an SMTP server so I can check if the account/password is a valid one?

查看:212
本文介绍了我如何排序'平'的SMTP服务器,以便我可以检查帐户/密码是一个有效的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个小WPF电子邮件发件人教程,但我不希望分享它,如果它有这个明显的错误。

目前,这是发生了什么。

  1. 在用户的用户名和密码类型。
  2. 标签loginstatus更改为已登录不管是gibeerish与否。
  3. 在邮件正文并发送至字段启用。
  4. 在用户pressed发送按钮,如果有异常(例如,错误的用户名/密码)的消息框显示它,loginstatus变回注销。

这是非常非常错误的,我想解决这个问题。

我只是'平'

如何,看是否有凭据是正确的(不发送测试电子邮件)。

我使用smtp.gmail.com端口587

修改 以下是我发送电子邮件。

  VAR的客户=新SmtpClient(smtp.gmail.com,587)
        {
            证书=新的NetworkCredential(用户名,密码),
            EnableSsl =真
        };

        尝试
        {
            client.Send(fromEmail,toEmail,主题,正文);
        }
        赶上(例外五)
        {
            的MessageBox.show(e.Message);
        }
 

解决方案

您不能System.Net.Mail做到这一点。你要么推出自己或使用第三方产品(无耻插头:像mine-- www.aspnetmx.com

I'm trying to build a little WPF email sender tutorial but I don't want to share it if it has this glaring bug.

Currently, this is what happens.

  1. user types in username and password.
  2. label 'loginstatus' changes to "Logged in" regardless if it's gibeerish or not.
  3. Message body and send to fields are enabled.
  4. user pressed "Send" button and if there is an exception (for example, wrong username/password) the messagebox shows it, and loginstatus is changed back to logged out.

This is very very wrong and I want to fix it.

How can I just 'ping' to see if a credential is correct (without sending a test email).

I'm using smtp.gmail.com port 587

Edit Here's how I'm sending the emails.

var client = new SmtpClient("smtp.gmail.com", 587)
        {
            Credentials = new NetworkCredential(username, password),
            EnableSsl = true
        };

        try
        {
            client.Send(fromEmail, toEmail, subject, body);
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);                
        }       

解决方案

You can't do this with System.Net.Mail. You have to either roll your own or used a 3rd party product (shameless plug: like mine-- www.aspnetmx.com )

这篇关于我如何排序'平'的SMTP服务器,以便我可以检查帐户/密码是一个有效的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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