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

  • SEARCH
  • Home
  • 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 6365345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:16:52+00:00 2026-05-25T00:16:52+00:00

I send mails following this pattern: public static bool SendPasswordMail(MembershipUser user, Control owner, string

  • 0

I send mails following this pattern:

public static bool SendPasswordMail(MembershipUser user, Control owner, string password)
{
    var definition = new MailDefinition { BodyFileName = string.Concat(AccountRoot, "password.htm"), IsBodyHtml = true };
    var subject = "Your new password - {0}".FormatWith(ApplicationConfiguration.ApplicationName);

    var data = ExtendedData(DefaultData, subject, user);

    data.Add("<%Password%>", password);

    return definition.CreateMailMessage(user.Email, data, owner).Send(subject);
}

public static bool Send(this MailMessage message, string subject)
{
    try
    {
        using (message)
        {
            message.Subject = subject;

            using (var client = new SmtpClient())
            client.Send(message);
        }
    }
    catch
    {
        return false;
    }

    return true;
}

Rather than setting the subject to “Your new password – Website”, I’d like to set the from user name to “Website”, and the subject to just “Your new password”. But I can’t figure out how to set the from user name.

My smtp element in web.config looks like this:

<smtp deliveryMethod="Network" from="noreply@site.com">
     <network host="localhost" port="25" userName="noreply@site.com" password="******" />
</smtp>
  • 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-25T00:16:53+00:00Added an answer on May 25, 2026 at 12:16 am

    Take a look a the MailDefinition.CreateMailMessage Method definition on MSDN.

    It specifies that the second parameter (an IDictionary object, variable “data” in your sample code) should contain strings that are replaced in the email message.

    Using this object you could add a replacement for the from address like so:

    data.Add("<%From%>", "fromaddress@domain.com");
    

    However due to the ability to forge sender addresses using SMTP almost all mail exchangers will be using an email validation system such as Sender Policy Framework (SPF) to ensure that the emails received have been sent from a valid source.

    So you cannot use any email address in the from field if you wish your recipients to receive your emails. You must use an email address matching the domain you are sending from. DNS changes are also required to make the necessary checks possible.

    Checkout this link: An Overview of the Sender Policy Framework

    It states:

    SPF is easy to understand. The “Internet” uses DNS (Domain Name
    System) to resolve Domain Names (as an example http://www.msexchange.org)
    into IP addresses. DNS is also used to direct requests for different
    services like e-mail and Web Servers. For every Domain around the
    world an MX (Mail Exchanger) record must exist. An MX record tells the
    e-mail sender where the target server for receiving mail is located.

    SPF is publishing “reverse MX” records in DNS which tells the mail
    sender which machines send mail from the domain.

    The recipient of the e-mail can now check these records to ensure that
    e-mail is coming from a „trusted“ sender from this domain.

    These “reverse MX” records can be easily published in DNS. It takes
    only one line in DNS to fullfil all requirements. I will give you an
    example later in this article.

    SPF operates at the level of the SMTP transaction, and requires at
    most three pieces of information:

    The MAIL FROM: parameter of the incoming mail The HELO or EHLO
    parameter of the sending SMTP server (used for Mailer-Deamon bounces
    which send a blank MAIL FROM) The IP address of the sending SMTP
    server


    Edit

    There is no way to pass the sender alias (display name) to the MailDefinition on creation and Im not sure how to add the data to the IDictionary object, but the following should work (in the Send extension method):

    message.Subject = subject;
    message.From = new MailAddress(message.From.Address, "Display Name");
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got something like the following... public boolean sendmail (String host, String to, String
I'm using the following method to send mail from Python using SMTP. Is it
I know how to send mails using the Microsoft Enterprise Library 2.0 using a
A client of mine uses Oracle 9i's utl_smtp to send mails out notifications to
For testing purposes I want send mail to my localhost user account rather than
I have to write a script to send mails using unix shell scripts. The
I am using the MSOUTL.OLB library to send mails. The code used is the
I am trying to send E-mails asynchronously and it works fine as long as
I am trying to send a simple email through the following code: protected void
I've been getting the following exception when trying to send an e-mail using System.Net.Mail:

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.