Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 511361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:12:31+00:00 2026-05-13T07:12:31+00:00

Please suggest me a code for send mail script in asp.net with C# .

  • 0

Please suggest me a code for send mail script in asp.net with C#. I want to build inquiry form where i wanna send all information on my email Id with attachment, subject and body.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:12:32+00:00Added an answer on May 13, 2026 at 7:12 am
    try
    {
        // Assign a sender, recipient and subject to new mail message
        MailAddress sender =
            new MailAddress("sender@johnnycoder.com", "Sender");
    
        MailAddress recipient =
            new MailAddress("recipient@johnnycoder.com", "Recipient");
    
        MailMessage m = new MailMessage(sender, recipient);
        m.Subject = "Test Message";
    
        // Define the plain text alternate view and add to message
        string plainTextBody =
            "You must use an email client that supports HTML messages";
    
        AlternateView plainTextView =
            AlternateView.CreateAlternateViewFromString(
                plainTextBody, null, MediaTypeNames.Text.Plain);
    
        m.AlternateViews.Add(plainTextView);
    
        // Define the html alternate view with embedded image and
        // add to message. To reference images attached as linked
        // resources from your HTML message body, use "cid:contentID"
        // in the <img> tag...
        string htmlBody =
            "<html><body><h1>Picture</h1><br>" +
            "<img src=\"cid:SampleImage\"></body></html>";
    
        AlternateView htmlView =
            AlternateView.CreateAlternateViewFromString(
                htmlBody, null, MediaTypeNames.Text.Html);
    
        // ...and then define the actual LinkedResource matching the
        // ContentID property as found in the image tag. In this case,
        // the HTML message includes the tag
        // <img src=\"cid:SampleImage\"> and the following
        // LinkedResource.ContentId is set to "SampleImage"
        LinkedResource sampleImage =
            new LinkedResource("sample.jpg",
                MediaTypeNames.Image.Jpeg);
        sampleImage.ContentId = "SampleImage";
    
        htmlView.LinkedResources.Add(sampleImage);
    
        m.AlternateViews.Add(htmlView);
    
        // Finally, configure smtp or alternatively use the
        // system.net mailSettings
        SmtpClient smtp = new SmtpClient
              {
                  Host = "smtp.bigcompany.com",
                  UseDefaultCredentials = false,
                  Credentials =
                      new NetworkCredential("username", "password")
              };
    
        //<system.net>
        //    <mailSettings>
        //        <smtp deliveryMethod="Network">
        //            <network host="smtp.bigcompany.com"
        //              port="25" defaultCredentials="true"/>
        //        </smtp>
        //    </mailSettings>
        //</system.net>
    
        smtp.Send(m);
    }
    catch (ArgumentException)
    {
        throw new
            ArgumentException("Undefined sender and/or recipient.");
    }
    catch (FormatException)
    {
        throw new
            FormatException("Invalid sender and/or recipient.");
    }
    catch (InvalidOperationException)
    {
        throw new
            InvalidOperationException("Undefined SMTP server.");
    }
    catch (SmtpFailedRecipientException)
    {
        throw new SmtpFailedRecipientException(
            "The mail server says that there is no mailbox for recipient");
    }
    catch (SmtpException ex)
    {
        // Invalid hostnames result in a WebException InnerException that
        // provides a more descriptive error, so get the base exception
        Exception inner = ex.GetBaseException();
        throw new SmtpException("Could not send message: " + inner.Message);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 273k
  • Answers 273k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I asked Best “official” scripting language for Windows programmers, and… May 13, 2026 at 2:07 pm
  • Editorial Team
    Editorial Team added an answer If this is the default core DNN blog then there… May 13, 2026 at 2:07 pm
  • Editorial Team
    Editorial Team added an answer The result set is empty. So you need to check… May 13, 2026 at 2:07 pm

Related Questions

I am developing on BlackBerry 4.7 Storm device. Reminder: My application will allow user
I have a problem with WCF. I think I understand what the issue is,
Can anyone please suggest me a good sample code for zooming image in NSImageView.
I am looking for a sample code/implementation of open id as in stackoverflow. I
Please suggest me any opensource tool to generate C# code from UML designer,Or any

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.