0

我有 aspx 页面,我有这样的电子邮件字段

<input class="span12" type="text" placeholder="EMAIL" id="Email" name="Email" runat="server" />

在我的 Csharp 文件中,我有代码并使用 Request["Email"] 在访问者输入电子邮件地址时获取地址,可以是任何地址,所以我也想通过电子邮件发送给他们,我的代码如下所示,但它不起作用,我我正在使用.net 4.0,我可以在其中更改该动态电子邮件,无论我可以获取它并发送电子邮件。

private void SendEmail(int RefNum)
{
    var customerEmail = Request["Email"]; //getting value from aspx page.
    MailMessage ObjEmail = new MailMessage();
    ObjEmail.SendFrom = "carlaza@hotmail.ca";
    ObjEmail.SendTo = "zjaffary@hotmail.com";
    ObjEmail.SendCC = "jaffary_zafar@hotmail.com";
    ObjEmail.SendBCC =  customerEmail ;
    ObjEmail.Subject = "test Subject ";
    //Development
    //SmtpMail.SmtpServer = "tormail.corp.kkt.ca";
    //Production At Bell
    SmtpMail.SmtpServer = "tormail.corp.kkt.ca";

    ObjEmail.BodyFormat = MailFormat.Html;

    string strBody1 = "Test message " ;
    ObjEmail.Priority = MailPriority.High;

try {
    SmtpMail.Send(ObjEmail);
    lblResponse.Text = "Thank you for sending the form !";
    Response.AddHeader("Refresh", "2;URL=index.aspx");

    }

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

}
4

3 回答 3

0

你可以看到代码并且可以工作

SmtpClient SmtpServer = new SmtpClient("smtp.live.com");
var mail = new MailMessage();
mail.From = new MailAddress("youremail@hotmail.com");
mail.To.Add("to@gmail.com");
mail.Subject = "Test Mail - 1";
mail.IsBodyHtml = true;
string htmlBody;
htmlBody = "Write some HTML code here";
mail.Body = htmlBody;
SmtpServer.Port = 587;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential("youremail@hotmail.com", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);

请看题目。我认为这对你有帮助。 如何添加smtp hotmail账号发送邮件 如何添加smtp hotmail账号发送邮件

于 2013-06-17T04:13:51.413 回答
0

尝试这个

    protected void sendEmail(string subject, string ToEmail, string msg)
    {
        String body = msg;
        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();
        MailAddress fromAddress = new MailAddress("your_email_id");
        smtpClient.Host = "smtp.gmail.com";//host
        smtpClient.Port = 587;//port no. default 25
        smtpClient.UseDefaultCredentials = false;
        smtpClient.EnableSsl = true;
        smtpClient.Credentials = new System.Net.NetworkCredential("your_email_id", "password");
        message.From = fromAddress;
        message.To.Add(ToEmail);//if more than comma seprated
        message.Subject = subject;
        message.Priority = MailPriority.High;
        message.Body = body;
        message.IsBodyHtml = true;
        smtpClient.Send(message);
    }
于 2013-06-17T04:35:50.453 回答
0

您应该使用来自 Web 邮件服务器的身份验证信息。(用户名和密码)如果不是,那不是真正的电子邮件。

于 2013-06-17T03:55:20.100 回答