Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 02-02-2010
Member
 
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.
Reply With Quote
  #2  
Old 02-02-2010
Member
 
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 );
Reply With Quote
  #3  
Old 02-02-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
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();
    }
Reply With Quote
  #4  
Old 02-02-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
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.
Reply With Quote
  #5  
Old 02-02-2010
Member
 
Join Date: May 2008
Posts: 2,008
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;
        }
Reply With Quote
  #6  
Old 02-02-2010
Member
 
Join Date: May 2008
Posts: 2,293
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);
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Send An Email in C#"
Thread Thread Starter Forum Replies Last Post
Unable to send email with jpeg's/mp3's attachment to a Verizon phone using Opera's email client Tawannah Technology & Internet 4 23-08-2011 08:04 AM
Unable to send email from email alias via Microsoft Office 365 FrancoL Windows Software 6 10-07-2011 08:26 PM
"send page by email" and "send link by email" disabled in Internet Explorer 8 Bindaas-ER Technology & Internet 4 27-02-2011 04:32 AM
Windows live mail couldn't send email but can receive email danielyen Windows Software 1 15-07-2010 12:17 AM
Cannot send internal email to a external email host like hotmail, gmail, yahoo, gmx etc... Antonio00 Small Business Server 2 14-02-2008 09:16 PM


All times are GMT +5.5. The time now is 12:56 AM.