You must Sign In to post a response.
  • Category: ASP.NET

    How to configure for send mail in in C#

    Hi

    In my application I want to send mail with my mail Id means default.I dont know how to configure the Smtp.

    I have following fields
    1.FROM
    2.Subject
    3.To
    4.Body

    Give the Explanation also.

    Regards
    vinodh
  • #648047
    hi



    protected void SendMail_Click(object sender, EventArgs e)
    {
    try
    {
    MailAddress SendFrom = new MailAddress(txtFrom.Text);
    MailAddress SendTo = new MailAddress(txtTo.Text);

    MailMessage MyMessage = new MailMessage(SendFrom, SendTo);

    MyMessage.Subject = txtSubject.Text;
    MyMessage.Body = txtBody.Text;

    Attachment attachFile = new Attachment(txtAttachmentPath.Text);
    MyMessage.Attachments.Add(attachFile);

    SmtpClient emailClient = new SmtpClient(txtSMTPServer.Text);
    emailClient.Send(MyMessage);

    litStatus.Text = "Message Sent";
    }
    catch (Exception ex)
    {

    }
    }

    Regards
    Sagar pawar
    Software developer

  • #648051
    [Response removed by Admin. Read forum policies.]
    With Regards
    Kushal

  • #648064
    Please make sure that in the IIS you have SMTP install and configured.

    Add the IP "127.0.0.1" in the relay of the configuration.

    please check the sample code here.


    using System;
    using System.Web.Mail;


    public void sendMail()
    {
    try
    {
    MailMessage oMsg = new MailMessage();

    oMsg.From = "anil@dotnetspider.com";

    oMsg.To = "tony@dotnetspider.com";
    oMsg.Subject = "Send Using Web Mail";

    oMsg.BodyFormat = MailFormat.Html; //HTML FORMAT

    oMsg.Body = "<HTML><BODY><B>Hello World!</B></BODY></HTML>";


    String sFile = @"C:\temp\Hello.txt";
    MailAttachment oAttch = new MailAttachment(sFile, MailEncoding.Base64);

    oMsg.Attachments.Add(oAttch);


    SmtpMail.SmtpServer = "MySMTPServer";
    SmtpMail.Send(oMsg);

    oMsg = null;
    oAttch = null;
    }
    catch (Exception e)
    {
    Console.WriteLine("{0} Exception caught.", e);
    }
    }

    }

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #648118
    Hi,

    send email in C# code

    Please check below code:


    MailMessage mail = new MailMessage();
    mail.From = ""; // from address
    mail.To = ""; // to address
    mail.Subject = ""; // subject
    mail.Body = ""; // body of email
    SmtpMail.SmtpServer = ""; // smtp serve

    // send the mail
    SmtpMail.Send(mail);


    Thanks
    Rajesh

    Regards
    Mr.Rajesh
    Software Engg.

  • #648389
    Hai Vinodh,

    first of all the SMTP server should be installed to send/receive mail in your system.

    to install the SMTP server, go to the windows components in the control panel, and find the SMTP , check the checkbox and install it.

    After the installation, you need to set the configuration for port and server address(IP address) etc.

    these configurations are required in the code for send mail.
    Hope it will help.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.