使用默认发件人地址发送邮件

时间:2014-05-16 05:47:18

标签: c# email

我正在尝试在我的网站上发送邮件。现在问题是我不想输入起始地址,我希望默认情况下从文本框中获取起始地址。

以下是我到目前为止尝试的代码:

protected void btnMail_Click(object sender, EventArgs e) {
    try {
        MailMessage Msg = new MailMessage();
        Msg.From = lblFrom.Text;
        Msg.To = txtTo.Text;
        Msg.Subject = txtSubject.Text;
        Msg.Body = txtBody.Text;

        SmtpMail.SmtpServer = "10.20.72.1";
        SmtpMail.Send(Msg);

        Msg = null;

        Page.RegisterStartupScript("UserMsg", "<script>alert('Mail sent thank you...'); if(alert){ window.location='SendMail.aspx'; }</script>");

        } catch (Exception ex) {
            Console.WriteLine("{0} Exception caught.", ex);
        }
    }

任何人都可以帮我自动获取发件人的电子邮件ID。

编辑:

我只是在浏览它的方式,我在web中找到了一些代码。但我不明白如何在我的代码中实现它。 以下是代码:

WebMail.SmtpPort = 25;
        WebMail.UserName = "your-user-name-here";
        WebMail.Password = "your-account-password";
        WebMail.From = "your-email-address-here";

我可以知道如何在我的代码中实现这一点。

1 个答案:

答案 0 :(得分:0)

protected void Page_Load(object sender, EventArgs e)
{
    lblFrom.Text = "youremail@gmail.com";
}