使用ASP.Net中的Gmail SMTP邮件服务器发送电子邮件 [英] Send email using Gmail SMTP Mail Server in ASP.Net

查看:101
本文介绍了使用ASP.Net中的Gmail SMTP邮件服务器发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里编码:

Im coded here:

private void Send()
    {
        try
        {
            string Subject = "This is test mail using smtp settings",
            Body = "sad",
            ToEmail = txtEmail.Text.Trim();

            string SMTPUser = "eDMS.tanphu@gmail.com", SMTPPassword = "myPass";

            //Now instantiate a new instance of MailMessage
            MailMessage mail = new MailMessage();

            //set the sender address of the mail message
            mail.From = new MailAddress(SMTPUser, "iDOC");

            //set the recepient addresses of the mail message
            mail.To.Add(ToEmail);

            //set the subject of the mail message
            mail.Subject = Subject;

            //set the body of the mail message
            mail.Body = Body;

            //leave as it is even if you are not sending HTML message
            mail.IsBodyHtml = true;

            //set the priority of the mail message to normal
            mail.Priority = MailPriority.Normal;

            //instantiate a new instance of SmtpClient
            SmtpClient smtp = new SmtpClient();

            //if you are using your smtp server, then change your host like "smtp.yourdomain.com"
            smtp.Host = "smtp.gmail.com";

            //chnage your port for your host
            smtp.Port = 25; //or you can also use port# 587

            //provide smtp credentials to authenticate to your account
            smtp.Credentials = new System.Net.NetworkCredential(SMTPUser, SMTPPassword);
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            //if you are using secure authentication using SSL/TLS then "true" else "false"
            smtp.EnableSsl = true;

            smtp.Send(mail);
        }
        catch (SmtpException ex)
        {
        }
    }



我使用端口587

我的代码不是错误但不起作用。猜猜怎么办?

谢谢


Im used port 587
My code is not error but is not work. Any guess what to do?
Thanks

推荐答案

SmtpClient smtp = new SmtpClient();

smtp。主持人=smtp.gmail.com;

smtp.Port = 587; //端口应该是587.尝试此端口号
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587; //port should be 587.Try this port number once


谢谢所有

我创建了另一封电子邮件,它工作了
Thanks all
I created another email, it worked


这篇关于使用ASP.Net中的Gmail SMTP邮件服务器发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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