asp c#发送电子邮件而不配置发件人凭据

时间:2018-06-06 17:43:32

标签: c# email

我正在尝试测试从通用电子邮件(例如noreply@company.com)向用户发送电子邮件。 我想在按钮单击事件中执行此操作。如何在不使用凭据的情况下实现此目的? 我尝试了几件事,但总是遇到错误。

System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage();
        mm.To.Add(new System.Net.Mail.MailAddress("Email Address", "Name"));
        mm.From = new System.Net.Mail.MailAddress("Email Address");
        mm.Sender = new System.Net.Mail.MailAddress("Email Address", "Name");
        mm.Subject = "This is Test Email";
        mm.Body = "<h3>This is Testing SMTP Mail Send By Me</h3>";
        mm.IsBodyHtml = true;
        mm.Priority = System.Net.Mail.MailPriority.High; // Set Priority to sending mail
        System.Net.Mail.SmtpClient smtCliend = new System.Net.Mail.SmtpClient();
        smtCliend.Host = "Your smtp server";
        smtCliend.Port = 25;    // SMTP port no            
        smtCliend.Credentials = new NetworkCredential("User Name", "Password");
        smtCliend.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        try
        {
            smtCliend.Send(mm);
        }
        catch (System.Net.Mail.SmtpException ex)
        {
            lblMsg.Text = ex.ToString();
        }
        catch (Exception exe)
        {
            lblMsg.Text = "\n\n\n" + exe.ToString();
        }

由于

0 个答案:

没有答案