1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Sending email using c#

Discussion in 'C, C++, C#' started by perfectpoint, Jan 15, 2011.

  1. perfectpoint

    perfectpoint Junior Member

    Joined:
    Sep 21, 2010
    Messages:
    130
    Likes Received:
    27
    I am using windows application i want to know how can I send email using windows application of c#, can anyone help me regarding this?
     
  2. smack

    smack Junior Member

    Joined:
    Feb 1, 2010
    Messages:
    182
    Likes Received:
    78
    Occupation:
    Software Engineer/Evil Genius
    Location:
    inside .NET
    via which type of mail protocol? there are several options.

    if you google, there are loads of answers.

    start with the System.Net.Mail namespace.
     
  3. cyberroot

    cyberroot BANNED BANNED

    Joined:
    Jul 24, 2010
    Messages:
    345
    Likes Received:
    72
    lol its very easy ! bro search google u can find chilcat component to do all the web work for you !
     
  4. hatemachine

    hatemachine Regular Member

    Joined:
    Jan 14, 2011
    Messages:
    271
    Likes Received:
    1,138
    They're not free though.
     
  5. heedcase

    heedcase Registered Member

    Joined:
    Aug 31, 2009
    Messages:
    71
    Likes Received:
    5
    check out the 'openpop' pop3 libraries they are free and open souce..
     
  6. neutralhatter

    neutralhatter Jr. VIP Jr. VIP Premium Member

    Joined:
    Jun 23, 2010
    Messages:
    430
    Likes Received:
    330
    Here you go.

    // create mail message object
    MailMessage mail = new MailMessage();
    mail.From = ""; // put the from address here
    mail.To = ""; // put to address here
    mail.Subject = ""; // put subject here
    mail.Body = ""; // put body of email here
    SmtpMail.SmtpServer = ""; // put smtp server you will use here
    // and then send the mail
    SmtpMail.Send(mail);
     
  7. smack

    smack Junior Member

    Joined:
    Feb 1, 2010
    Messages:
    182
    Likes Received:
    78
    Occupation:
    Software Engineer/Evil Genius
    Location:
    inside .NET

    i don't believe you can assign the .To property of the MailMessage class directly to a string value.

    if i recall correctly it has to either be passed to the constructor of the MailMessage when it is instantiated, or added using the .Add() method.

    e.g.:

    Code:
    MailMessage mail = new MailMessage();
    mail.To.Add(recip);
    also, the .From and .ReplyTo properties are of the type MailAddress. i don't believe they can be assigned to a string either. probably depends on the version of the framework you're in, but in the last few implementations i have done, i have used the MailAddress class. you could probably also use a cast.

    e.g.:

    Code:
    MailAddress mailAddress = new MailAddress("helloworld@gmail.com");
    mail.From = mailAddress;
    mail.ReplyTo = mailAddress;