从asp.net页面通过SMTP通过Gmail发送邮件 [英] Sending mail from Gmail via SMTP from asp.net page

查看:97
本文介绍了从asp.net页面通过SMTP通过Gmail发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望经过一个月的努力而未能成功解决,这个网站将成为我的救星吗?

我在Visual Web dev 2010内置的asp.net开发服务器上运行着一个aspx页面.

我不断收到"SMTP服务器需要安全连接或客户端未通过身份验证.服务器响应为:5.5.1需要身份验证"

这总是在以下行上发生:SMTPServer.Send(myMessage)

我的web.config :(密码正确,出于明显原因,我刚刚将其隐藏在这里)

I''m hoping after a month of trying to resolve this with no success, this site will be my saviour?

I have an aspx page running on the asp.net development server built in to visual web dev 2010.

I keep getting "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required"

This always happens on this line: SMTPServer.Send(myMessage)

my web.config: (the password is correct, I have just hidden it here for obvious reasons)

<system.net>
        <mailSettings>
            <smtp>
                <network defaultCredentials ="false" host="smtp.gmail.com" port="587" userName="[DELETED]@gmail.com" password="********" />
            </smtp>
        </mailSettings>
    </system.net>




背后的代码:




code behind:

'create an SMTP client object
        Dim SMTPServer As New System.Net.Mail.SmtpClient(host)
        'configuration for the Google mail server
        SMTPServer.Host = host
        SMTPServer.Port = port
        SMTPServer.EnableSsl = True
        SMTPServer.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
        SMTPServer.UseDefaultCredentials = defaultCredentials
        SMTPServer.Credentials = New System.Net.NetworkCredential("username", "password")

推荐答案

我尝试了此方法,并成功了:

I tried this and it worked :

Dim Email As New System.Net.Mail.MailMessage("myMail@gmail.com", "otherMail@hccnet.nl")
Email.Subject = "test subject"
Email.Body = "this is a test"
Dim mailClient As New System.Net.Mail.SmtpClient()
Dim basicAuthenticationInfo As New System.Net.NetworkCredential("myUsername", "myPassword")
mailClient.Host = "smtp.gmail.com"
mailClient.Port = 587
mailClient.EnableSsl = True
mailClient.UseDefaultCredentials = False
mailClient.Credentials = basicAuthenticationInfo
mailClient.Send(Email)



您的专线



Your Line

SMTPServer.Credentials = New System.Net.NetworkCredential("username", "password")


不应该将用户名"和密码"作为用户名和密码吗?

干杯


Shouldn''t "username" and "password" just be username and password?

Cheers


这篇关于从asp.net页面通过SMTP通过Gmail发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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