简体   繁体   English

在没有密码的情况下在ASP.net中发送电子邮件

[英]Send email in ASP.net without password

I may be Wrong but I am stuck in an issue... I want to send the email to the user using ASP.net without having the password HERE is my code 我可能错了,但是我陷入了一个问题...我想使用ASP.net将电子邮件发送给用户,而无需输入密码,这是我的代码

But I do not have the password .How can I send email to the user without having their password. 但是我没有密码。如何在没有密码的情况下向用户发送电子邮件。

protected void submit_Click(object sender, Event Args e)
{
    MailMessage mail = new MailMessage();
    mail.To.Add(txtTo. Text);
    mail.From = new Mail Address(txt_from.Text);
    mail.Subject = txtSubject. Text;
    mail.Body = txtBody.Text;
    mail.IsBodyHtml = true;
    if (fileUpload1.HasFile)
    {
        mail.Attachments.Add(new Attachment(fileUpload1.PostedFile.InputStream, fileUpload1.FileName));
    }
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "mysmtp.gmail.com"; //Or Your SMTP Server Address
    smtp.Credentials = new System.Net.NetworkCredential("email", "password");
    //Or your Smtp Email ID and Password
    smtp.EnableSsl = true;
    smtp.Send(mail);
}

You don't need their password to send email. 您不需要他们的密码即可发送电子邮件。 You need password to your stmp server . 您需要密码到stmp服务器 You have to sing in to it to send any mail. 您必须唱歌才能发送任何邮件。 Try to create an email address for test puproses and use it credentials to send email. 尝试为测试对象创建一个电子邮件地址,并使用其凭据发送电子邮件。

There is part which you should fix for gmail stmp server: 对于Gmail stmp服务器,您应该修复以下部分:

smtp.Host = "smtp.gmail.com";
stmp.Port = 465;
stmp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential
             ("example@gmail.com", "exampleGmailPassword");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM