0

I have aspx page where i have the email field like this

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

In my Csharp file i have code and using Request["Email"] to get the address when visitor enter the email address which can be any so i want to email them as well my code is like Below, But it does not work, I am using .net 4.0, where i can change then that dynamic email whatever it would be i could get it and send email.

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());
    }

}

3 Answers3

0

You should use authetication information from web mail server. (user name and password) If not, that is not actual e-mail.

0

You can see the code and can work

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);

Please see the topic. I think it is helpfull for you. How to add smtp hotmail account to send mail How to add smtp hotmail account to send mail

Community
  • 1
  • 1
0

try this

    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);
    }
sangram parmar
  • 8,462
  • 2
  • 23
  • 47