English 中文(简体)
• 如何在伙伴关系中使用电子邮件SMTP。 NET表格
原标题:How to use gmail SMTP in ASP.NET form

我是一家新老会,正在打上一种工作形式。 在这里,在我们使用购买力平价时,我们没有一个是伙伴关系专家。 但是,我也处于项目组合经验的底线,主要是仅仅与超文本/中央支助事务合作。 我的目前形式代表如下:

rotected Sub SubmitForm_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not Page.IsValid Then Exit Sub

        Dim SendResultsTo As String = "email to"
        Dim smtpMailServer As String = "email server"
        Dim smtpUsername As String = "email username"
        Dim smtpPassword As String = "password"
        Dim MailSubject As String = "Form Results"

我将如何把这一表格发送给电子邮件地址? 我知道,我必须包括港口(587),但不能说,由于这一形式与我所看到的其他任何形式相匹配。 任何帮助都将受到高度赞赏。

最佳回答
protected void SendMail()
        {
            MailMessage msg = new MailMessage();
            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
            try
            {
                msg.Subject = "Add Subject";
                msg.Body = "Add Email Body Part";
                msg.From = new MailAddress("Valid Email Address");
                msg.To.Add("Valid Email Address");
                msg.IsBodyHtml = true;
                client.Host = "smtp.gmail.com";
                System.Net.NetworkCredential basicauthenticationinfo = new System.Net.NetworkCredential("Valid Email Address", "Password");
                client.Port = int.Parse("587");
                client.EnableSsl = true;
                client.UseDefaultCredentials = false;
                client.Credentials = basicauthenticationinfo;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.Send(msg);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }
        }
问题回答

您可在web.config上添加这一内容。 档案

 <system.net>
    <mailSettings>
      <smtp from="[email protected] ">
        <network host="smtp.gmail.com" defaultCredentials="false"
      port="587" userName ="[email protected]" password="yourpassword" />
      </smtp>
    </mailSettings>
   </system.net>

建立一个系统.Net.mail.SmtpClient物体,将员工和管理当局协调会服务器安装在你使用中。

Then create a System.Smtl.MailMessage with the message data and send it:

using (System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient()) {
    using (System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("from*where.com", "[email protected]") {
        IsBodyHtml = true,
        Subject = "Subject text",
        Body = messageBody,
    }) {
        mail.Send(message);
} // using

你可以在建筑商中没收你的SmtpClient,我们使用网络.comfig,因此我没有这种编号。

Google now blocks sign-ins from an app (even over SSL) to send an email. You have two options:

  1. Enable less-secure apps for the account you are using; OR
  2. Generate an app-password from Google (recommended)

For option 2, you will have to enable 2-factor authentication before you can generate an app pasword. Here are the steps I took to get this working on my ASP.NET web app

• 如何召集一个协会。 电子邮件:SMTP上的网络链接

如果你重新使用两步核查,就不要忘记产生具体的申请密码,也不使用你在电子邮件上使用的密码。

(我可以补充这一意见。) 在张贴时没有足够回响。

,没有缺少关于如何从内部发送电子邮件的指南。 NET。

基本上,您希望有<代码>System.Net.mail.SmtpClient 反对与员工和管理当局协调会服务器互动,即<代码>System.Net.mail.Message反对持有电文数据,并将电文上的数据配置在您的专栏中,指示客户如何/在何处发送电文。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签