什么是STARTTLS命令。我无法从smtp gmail服务器发送电子邮件 [英] what is STARTTLS command.Iam not able to send email from smtp gmail server

查看:333
本文介绍了什么是STARTTLS命令。我无法从smtp gmail服务器发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用http位置从smtp gmail server.iam发送电子邮件。



我发现此错误:SMTP服务器需要安全连接或客户端服务器响应是:5.7.0必须首先发出STARTTLS命令.os1sm57959508pac.20 - gsmtp



如何解决这个问题.. ??



我的页面和代码如下

代码落后(aspx.cs):



使用System;

使用System.Collections.Generic;

使用System.Linq;

使用System.Web;

使用System.Web.UI;

使用System.Web.UI.WebControls;



使用System.Net .Mail;

使用System.Configuration;



公共部分类smtpcredinwebconfig:System.Web.UI.Page

{

protected void Page_Load(object sender,EventArgs e)

{



}

protected void btnSend_Click(object sender, EventArgs e)

{

试试

{



MailMessage ObjMailMessage = new MailMessage();



ObjMailMessage.From = new MailAddress(ConfigurationManager.AppSettings [FromMail]。ToString(),ASP.NET Mail);

ObjMailMessage.To.Add(new MailAddress(txtTo.Text.Trim()));

ObjMailMessage.Subject = txtSubject.Text.Trim();

ObjMailMessage.Body = txtMsg.Text.Trim();



if(fUAttachment.HasFile)

{

ObjMailMessage.Attachments.Add(新附件(fUAttachment.PostedFile.InputStream,fUAttachment.PostedFile.FileName));

}



ObjMailMessage.IsBodyHtml = false;

ObjMailMessage.Priority = MailPriority.High;



SmtpClient ObjSmtpClient = new SmtpClient();


ObjSmtpClient.Host = ConfigurationManager.AppSettings [Host]。ToString();

ObjSmtpClient.Port = int.Parse(ConfigurationManager。 AppSettings [Port]。ToString());



ObjSmtpClient.Send(ObjMailMessage);



lblStatus.Text =邮件已成功发送;

lblStatus.ForeColor = System.Drawing.Color.Green;

}

catch(例外情况ex)

{

lblStatus.Text = ex.Message;

lblStatus.ForeColor = System.Drawing.Color.Red;

}

}

}





来源查看(aspx):



I want to send email from smtp gmail server.iam using http location.

I found this error: "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. os1sm57959508pac.20 - gsmtp"

How to solve this..??

My page and code is as follows
code behind (aspx.cs):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Net.Mail;
using System.Configuration;

public partial class smtpcredinwebconfig : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnSend_Click(object sender, EventArgs e)
{
try
{

MailMessage ObjMailMessage = new MailMessage();

ObjMailMessage.From = new MailAddress(ConfigurationManager.AppSettings["FromMail"].ToString(), "ASP.NET Mail");
ObjMailMessage.To.Add(new MailAddress(txtTo.Text.Trim()));
ObjMailMessage.Subject = txtSubject.Text.Trim();
ObjMailMessage.Body = txtMsg.Text.Trim();

if (fUAttachment.HasFile)
{
ObjMailMessage.Attachments.Add(new Attachment(fUAttachment.PostedFile.InputStream, fUAttachment.PostedFile.FileName));
}

ObjMailMessage.IsBodyHtml = false;
ObjMailMessage.Priority = MailPriority.High;

SmtpClient ObjSmtpClient = new SmtpClient();

ObjSmtpClient.Host = ConfigurationManager.AppSettings["Host"].ToString();
ObjSmtpClient.Port = int.Parse(ConfigurationManager.AppSettings["Port"].ToString());

ObjSmtpClient.Send(ObjMailMessage);

lblStatus.Text = "Mail Sent Successfully";
lblStatus.ForeColor = System.Drawing.Color.Green;
}
catch (Exception ex)
{
lblStatus.Text = ex.Message;
lblStatus.ForeColor = System.Drawing.Color.Red;
}
}
}


Source View(aspx):

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="smtpcredinwebconfig.aspx.cs" Inherits="smtpcredinwebconfig" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
        <tr><td colspan="2"><asp:Label ID="lblStatus" runat="server"></asp:Label></td></tr>
        <tr>
            <td>To</td>
            <td><asp:Textbox ID="txtTo" runat="server"></asp:Textbox></td>
        </tr>
        <tr>
            <td>Subject</td>
            <td><asp:Textbox ID="txtSubject" runat="server"></asp:Textbox></td>
        </tr>
        <tr>
            <td>Message</td>
            <td><asp:Textbox ID="txtMsg" runat="server" TextMode="MultiLine"></asp:Textbox></td>
        </tr>
        <tr>
            <td>Attach Files</td>
            <td><asp:FileUpload ID="fUAttachment" runat="server" /></td>
        </tr>
         <tr><td></td><td><asp:Button ID="btnSend" runat="server" Text="Send" OnClick="btnSend_Click"></asp:Button></td></tr>

    </table>
    </div>
    </form>
</body>
</html>





Web.config:





Web.config:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
        <identity impersonate="false" />
  </system.web>
  <appSettings>
    <add key="FromMail" value="vinod475.2009@gmail.com" />
    <add key="Host" value="smtp.gmail.com" />
    <add key="Port" value="587" />
  </appSettings>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network">
        <network defaultCredentials="false" host="smtp.gmail.com" password="& port="587" userName="vinod475.2009@gmail.com"  />
      </smtp>
    </mailSettings>
  </system.net>
    <!--<system.webServer>
        <directoryBrowse enabled="true" />
    </system.webServer>-->
</configuration>

推荐答案

这篇关于什么是STARTTLS命令。我无法从smtp gmail服务器发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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