在ASP.NET中发送邮件的步骤是什么? [英] What are the steps for sending mail in ASP.NET?

查看:78
本文介绍了在ASP.NET中发送邮件的步骤是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此编码成功运行,并显示邮件已成功发送,但收件箱中找不到邮件.

在这里我无法理解用户名&密码逻辑,因为我给了它
Gmail帐户的用户名,密码(错误的用户名,密码)
然后成功运行,那么给出用户名和密码的原因是什么
还是可以更改通过Gmail帐户发送邮件的后端设置?


This coding run successfully and show mail send successfully, but mail not found in inbox.

Here I can''t understand username & password logic because I gave it
Gmail account username, password anything else(Wrong userid,password)
then it run successfully so what give the username and password
or what can I changes for backend setting for send mail through my Gmail account?


using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Net.Mail;

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


        SmtpClient smtp = new SmtpClient("192.168.1.2",Convert.ToInt32(25));
        System.Net.NetworkCredential cre = new System.Net.NetworkCredential("uamrit@gmail.com", "password");
        smtp.Credentials = cre;
        MailMessage message = new MailMessage();
        message.To.Add(new MailAddress("uamrit@gmail.com"));
        message.IsBodyHtml = true;
        message.Body = "<html><head><body><p> this is Demo for sending mail. </p></body></head></html>";
        message.Subject = ("response from the web sitre");
        message.From = new MailAddress("uamrit@gmail.com");



        try
        {
            smtp.EnableSsl = false;
          
            smtp.UseDefaultCredentials =false ;
            smtp.Send(message);
            Response.Write("Your Email has been sent sucessfully -");

        }
        catch (Exception exc)
        {
            Response.Write("Send failure: " + exc.ToString());

        }
    }



在webconfig




in webconfig


<mailsetting>
<smtp from="uamrit@gmail.com">
<network host="192.168.1.2" port="25" username="uamrit" password="password" />
</smtp>
</mailsetting>

推荐答案

您需要提供正确的SMTP服务器以及有效的用户名和密码才能使电子邮件正常工作.

请参考 [
You need to provide proper SMTP Server and valid username and password to make the email work.

Refer this[^]


Mark it as answer if it is helpful


将其他用户添加到您要发送邮件的whome中.
并使用smtp客户端作为"Smtp.gmail.com"
add different user to whome you are sending mail.
and use smtp client as "Smtp.gmail.com"


:thumbsup:我同意以上回答,发件箱必须打开SMTP服务器.您可以在Gmail邮件中进行设置.
:thumbsup:I agree the above answer,The sendbox must open the SMTP Server.You can set it in Gmail mail.


这篇关于在ASP.NET中发送邮件的步骤是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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