如何在 ASP.NET 表单中使用 gmail SMTP

0

本文介绍了如何在 ASP.NET 表单中使用 gmail SMTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我是 ASP 新手,正在对工作表单进行故障排除.我们这里没有人是 ASP 专家,因为我们使用 PHP.但我的 PHP 经验也很差,主要是单独使用 HTML/CSS.我当前的表单凭据如下所示:

I am a ASP novice and am troubleshooting a form for work. None of us here are ASP experts as we use PHP. But I am on the bottom of PHP experience as well, mostly working with HTML/CSS alone. My current forms credentials look like:

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"

如何将此表单发送到 Gmail 地址?我知道我必须在某处包含端口(587),但不知道在哪里,因为这种形式与我见过的任何其他形式的语法都不匹配.任何帮助将不胜感激!

How would I go about making this form send to a Gmail address? I know I must include the port (587) somewhere, but cannot figure out where, as this form doesn't match the syntax of any other forms I have seen. Any help would be greatly appreciated!

推荐答案

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);
            }
        }

这篇关于如何在 ASP.NET 表单中使用 gmail SMTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

用 C# 编写全局自定义事件
Writing a global custom event in C#(用 C# 编写全局自定义事件)...
2023-11-11 C#/.NET开发问题
2

我可以使用 lambda 语法忽略委托参数吗?
Can I ignore delegate parameters with lambda syntax?(我可以使用 lambda 语法忽略委托参数吗?)...
2023-11-11 C#/.NET开发问题
7

在 C# 中附加事件处理程序的 2 种不同方式是否存在实际差异?
Is there an actual difference in the 2 different ways of attaching event handlers in C#?(在 C# 中附加事件处理程序的 2 种不同方式是否存在实际差异?)...
2023-11-11 C#/.NET开发问题
5

有和没有“新"的接线事件之间的区别
Difference between wiring events with and without quot;newquot;(有和没有“新的接线事件之间的区别)...
2023-11-11 C#/.NET开发问题
2

无边框形式的 Windows 7 样式 Dropshadow
Windows 7 style Dropshadow in borderless form(无边框形式的 Windows 7 样式 Dropshadow)...
2023-11-11 C#/.NET开发问题
1