Results 1 to 6 of 6

Thread: Send An Email in C#

  1. #1
    Join Date
    Nov 2009
    Posts
    652

    Send An Email in C#

    Hello, I was wondering about the code which can send an email with the help of the C# programming language. If anyone knows the different methods which can be helpful to achieve it, then please provide me that. I want to achieve this. But, as I am not having any information about the method to be used, it is not possible for me to get the solution. So, please provide me help to get different methods for sending an email in C# .net.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Send An Email in C#

    Hello, If you want to send a simple text email in C# then you may need to use the code below. It will provide you all the related methods and also gives you all the details about it.
    Code:
    MailMessage email = new MailMessage();
    mail.To = "<id of destination >";
    mail.From = "<id of source>";
    mail.Subject = "Testing";
    mail.Body = "Continue";
    SmtpMail.SmtpServer = "localhost";  
    SmtpMail.Send( mail );

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Send An Email in C#

    The following code works perfectly. You just need to change the SMTP client settings. I have tried it. It is working perfectly.

    Code:
    Using System.Net.Mail;
    Using System.Net;
    private void button2_Click(object sender, EventArgs e)
        {
          MailMessage mail;
          SmtpClient Smtp;
    
          Smtp = new SmtpClient("monserveursmtp.com", 25);
          Smtp.Credentials = new NetworkCredential("<email_id>", "abcd12345");
          Mail = new MailMessage("<email_id>", "<email_id>", "cuckoo", "cuckoo");
          Smtp.Send(Mail);
          Mail.Dispose();
        }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Send An Email in C#

    Hello, it is needed to make use of the methods below for getting the solution:
    Code:
    smtp.UseDefaultCredentials = true;
    smtp.EnableSsl = true;
    MailMessage mail = new MailMessage();
    I am not having whole code for it. But, I have these methods which can help you to create your own code.

  5. #5
    Join Date
    May 2008
    Posts
    2,012

    Re: Send An Email in C#

    Hello, I have the code which will solve your problem also you will get more knowledge about the sending email in c#. You just need to make use of it, as it is.
    Code:
    Public string SendMail(StringBuilder content, string Subject, string MailTo, string MailFrom, string SMTPServer, int PortServer)
    {
             string Back = string.Empty;
    MailMessage msg = null;
    Encoding Encoding = MyEncoding.GetEncoding("iso-8859-1");
                try
                {
                    msg = new MailMessage(MailFrom, MailTo);
                    msg.Body = Content.ToString();
                    msg.BodyEncoding = MyEncoding;
                    msg.IsBodyHtml = false;
                    msg.Subject = Subject;
                    SmtpClient smtp = new SmtpClient(SMTPServer, PortServer);
                    smtp.UseDefaultCredentials = true;
                    smtp.Send(msg);
                    Back = "Mail sent to" + MailTo;
                }
                catch (Exception ex)
                {
                    Back = "Error in Sendmail function - Details:" + Ex.ToString();
                }
                finally
                {
                    msg = null;
                    MyEncoding = null;
                }
                return Back;
            }

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: Send An Email in C#

    If you are making use of the vb.net then you need to make use of the code below which will simply send the email to the specified address.
    Code:
    Dim mail As New MailMessage()
    mail.To = "<email_id>"
    mail.From = "<email_id>"
    mail.Subject = "Testing "
    mail.Body = "Body"
    SmtpMail.SmtpServer = "localhost" 
    SmtpMail.Send(mail)
    But, as you required to have the c#.net code you need to make use of the code below for the same.
    Code:
    MailMessage emailmessage = new MailMessage();
    emailmessage.From = "";          
    emailmessage.To = "";            
    emailmessage.Subject = "";      
    emailmessage.Body = "";           
    SmtpMail.SmtpServer = ""; 
    SmtpMail.Send(emailmessage);

Similar Threads

  1. Replies: 4
    Last Post: 23-08-2011, 08:04 AM
  2. Replies: 6
    Last Post: 10-07-2011, 08:26 PM
  3. Replies: 4
    Last Post: 27-02-2011, 04:32 AM
  4. Windows live mail couldn't send email but can receive email
    By danielyen in forum Windows Software
    Replies: 1
    Last Post: 15-07-2010, 12:17 AM
  5. Replies: 2
    Last Post: 14-02-2008, 09:16 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,005,073.81879 seconds with 16 queries