无法使用smtp发送邮件 [英] Failed to send mail using smtp

查看:318
本文介绍了无法使用smtp发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用smtpclient发送邮件.这是我的代码.
发送时会显示类似
的错误 错误:
SMTP服务器需要安全连接,或者客户端未通过身份验证.服务器响应为:5.5.1需要身份验证.


谁能告诉我发送邮件有什么问题?

I am using smtpclient to send a mail.Here is my code.
while sending it will show an error like
Error:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.


can any one tell what is the problem to sending mail?

public int sendmail(string name, string pwd,string email)
    {
        int i = 0;
        MailMessage ms = new MailMessage();
        ms.From = new MailAddress(@"ValidEmailAddress");
        ms.To.Add(email);
        ms.Subject = "Username and Password";
        ms.SubjectEncoding = System.Text.Encoding.UTF8;
        ms.IsBodyHtml = true;
        ms.Body = "UserName='" + name + "' and Password='" + pwd + "'";
        ms.BodyEncoding = System.Text.Encoding.UTF8;
        ms.Priority = MailPriority.High;
        SmtpClient clt = new SmtpClient();
        clt.Credentials = new System.Net.NetworkCredential("ValidEmailAddress", "ValidPassword");
        clt.Port = 587;
        clt.Host = "ValidHost";
        clt.EnableSsl = true;
        try

        {
            clt.Send(ms); 
            ms.Dispose();
            i = 1;
        }
        catch(Exception err) 
        {
 
        }
        return i;



Reiss-删除了用户详细信息[/编辑]



Reiss - removed user details [/Edit]

推荐答案

看看本教程

The SMTP server requires a secure connection or the client was not authenticated.



此行表示您的smtp服务器仅允许安全连接

这意味着您的服务器具有一定的安全性,并且在发送邮件时需要启用它

例如,启用ssl安全性



this line says that either your smtp server allows only secured connection

that means your server has some security and while sending mail you need to enable it

eg to enable ssl security

smtpclientobj.Enablessl=true;



既然你做到了

检查您指定的凭据是对还是错.



and since you have did it

check the credentials specified by you is right or wrong.


使用
clt.UseDefaultCredentials = false;


并检查您的电势是否正确.


and also check your cardentials are right.


这篇关于无法使用smtp发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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