locked
How to change smtp sender RRS feed

  • Question

  • User-1404740798 posted

    I want to send mail using outlook smtp.

    I want the email address entered by the user to be the sender and my email address to be the recipient.

    Can I change the sender's email address?

    string _sender = "email";
                string _password = "password";
    
                string toMail = "recipient email";
    
                SmtpClient client = new SmtpClient("smtp-mail.outlook.com");
    
                client.Port = 587;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(_sender, _password);
                client.EnableSsl = true;
                client.Credentials = credentials;
    
                try
                {
                    var mail = new MailMessage(_sender.Trim(), toMail.Trim());
                    mail.Subject = Title;
                    mail.Body = Contents;
                    client.Send(mail);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    throw ex;
                }

    Friday, August 16, 2019 7:52 AM

All replies

  • User753101303 posted

    Hi,

    It is overriden by the actual Outlook account owner? I saw once someone with the same issue in gmail. IMO this is on purpose and most server are configured this way to prevent mail forgery.

    My first try would be to use https://docs.microsoft.com/en-us/dotnet/api/system.net.mail.mailmessage.replyto?view=netframework-4.8 which should allow to send a possible reply there. If you want to see the original mail right away, you likely have no other option than including this in the message...

    Friday, August 16, 2019 9:01 AM
  • User-1038772411 posted

    Hi, slkim

    if you want to change sender's email please refer below artical hope you will get your answer as per your requirement.

    https://stackoverflow.com/questions/8643279/change-the-sender-in-outlook-using-c-sharp

    Thanks.

    Friday, August 16, 2019 9:11 AM
  • User1520731567 posted

    Hi slkim,

    slkim

    I want to send mail using outlook smtp.

    I want the email address entered by the user to be the sender and my email address to be the recipient.

    Can I change the sender's email address?

    System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(_sender, _password);
    

    You need to make sure _sender and _password match.

    And It is not safe for users to fill in username and password on the front end.

    Best Regards.

    Yuki Tao

    Monday, August 19, 2019 7:19 AM
  • User-474980206 posted
    With several restrictions. The user email must be an account on the exchange mail server (same ad as the login). The login must be an exchange admin (impersonation permission).
    Monday, August 19, 2019 2:19 PM