首页 > 解决方案 > 使用 ASP.Net 发送电子邮件而不在代码中显示我的密码

问题描述

我的表格如下所示:在此处输入图像描述

当点击发送按钮时,会调用以下代码:

protected void btnSend_Click(object sender, System.EventArgs e)
    {
        // Command-line argument must be the SMTP host.
        SmtpClient client = new SmtpClient();
        // Specify the email sender.
        // Create a mailing address that includes a UTF8 character
        // in the display name.
        MailAddress from = new MailAddress(txtEmail.ToString().Trim(),
        txtName.ToString() + (char)0xD8,
        System.Text.Encoding.UTF8);
        // Set destinations for the email message.
        MailAddress to = new MailAddress("nyamathulani@gmail.com");
        // Specify the message content.
        MailMessage message = new MailMessage(from, to);
        message.Body = txtMsg.ToString();
        // Include some non-ASCII characters in body and subject.
        string someArrows = new string(new char[] { '\u2190', '\u2191', '\u2192', '\u2193' });
        message.Body += Environment.NewLine + someArrows;
        message.BodyEncoding = System.Text.Encoding.UTF8;
        message.Subject = txtSubject.ToString() + someArrows;
        message.SubjectEncoding = System.Text.Encoding.UTF8;
        // Set the method that is called back when the send operation ends.
        client.SendCompleted += new
        SendCompletedEventHandler(SendCompletedCallback);
        // The userState can be any object that allows your callback
        // method to identify this send operation.
        // The userToken is a string constant.
        string userState = "Thulani awaits your message";
        client.SendAsync(message, userState);
        btnSend.Text = "Sending...";

        // Clean up.
        message.Dispose();
    }

] 2我希望能够从 ASP.NET Web 表单发送电子邮件,而无需在代码中使用我的密码,因为我正在构建投资组合网站并且需要使用我的个人电子邮件地址

标签: c#asp.netemailwebformspasswords

解决方案


我认为无论如何您都必须在代码中输入密码,或者您必须手动设计,以便在发送电子邮件时输入密码。


推荐阅读