Send email with another account RRS feed

  • Question

  • User-1350042179 posted


    I would like to send email in c#, but with different from email.

    The credentials to connect to email are differents than credentials of from account.

    Wednesday, December 18, 2019 5:12 AM


All replies

  • User-719153870 posted

    Hi neoaguil17,

    The credentials to connect to email are differents than credentials of from account.

    What do you mean by "The credentials to connect to email"? The credential of the target email account?

    If so, there's no such limit that the credentials of target and from account must be the same.

    Please check Sending Email Using C# for more information using System.Net.Mail to send email in C#.

    Or if i misunderstood anything, please feel free to tell and provide a more detailed description.

    Best Regard,

    Yang Shen

    Thursday, December 19, 2019 1:46 AM
  • User409696431 posted

    "I would like to send email in c#, but with different from email.

    The credentials to connect to email are differents than credentials of from account."

    Your question is not clear.  When sending email, the "from" address is related to the server's credentials.  If you mean you don't want to send it from your domain's email, then change the credentials to the server for the email you do want to send if from.  For example if you want it to send from a gmail address, you'd use the gmail server and its credentials.  If you meant something else, perhaps you could clarify your question.

    Saturday, December 21, 2019 4:52 AM
  • User-1350042179 posted


    I would like to change the from property of the email:

    In other words different credentials than from adress:
    var _credential = new NetworkCredential
    UserName = "user@test.com.pe",
    Password = "pass"
    var _smtpClient = new SmtpClient(SendEmail_Host)
    EnableSsl = true,
    Port = 25,
    Credentials = _credential

    var _message = new MailMessage
    BodyEncoding = Encoding.UTF8

    _message.From = new MailAddress("user20@test.com.pe");

    Since I want to see a different sender when a user receive an email..

    Thursday, December 26, 2019 12:21 AM
  • User-719153870 posted

    Hi neoaguil17,

    The requirement is clear now but it's hard to deliver a solution. We know we can do this in gmail but not sure if it's the same for other server.

    As for gmail server, you can refer to change sender address when sending mail through gmail in c#.

    Or you can refer to below demo:

    Notice: The demo uses the code from Sending Email Using C# since the code you provided is not complete and they are the same just in different format.


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <form id="form1" runat="server">
                <asp:Button ID="Button2" runat="server" Text="Check" OnClick="Button2_Click" />


    protected void Button2_Click(object sender, EventArgs e)
                    MailMessage message = new MailMessage();
                    SmtpClient smtp = new SmtpClient();
                    message.From = new MailAddress("Mygmailaddress@gmail.com", "Myoutlookaddress@outlook.com");
                    message.To.Add(new MailAddress("MyMSFTaddress@microsoft.com"));
                    message.Subject = "Test";
                    message.IsBodyHtml = true; //to make message body as html  
                    message.Body = "This is a test message! Please ignore, sorry for any convenience. Current time is:" + DateTime.Now.ToString();
                    smtp.Port = 587;
                    smtp.Host = "smtp.gmail.com"; //for gmail host  
                    smtp.EnableSsl = true;
                    smtp.UseDefaultCredentials = false;
                    smtp.Credentials = new NetworkCredential("Mygmailaddress@gmail.com", "Mygmailpassword");
                    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                catch (Exception) { }

    As you can see, i used the gmail as the server and a gmail account as the smtp.Credentials but with a microsoft mail as the "From" display name to send to an outlook account.

    Below is the result of this demo:

    Below is how you can see the related setting in gmail:

    Best Regard,

    Yang Shen

    Thursday, December 26, 2019 5:39 AM
  • User-1350042179 posted


    I used Microsoft Graph to send email from different users.

    This is the link of the api:


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 13, 2020 2:27 AM