Display name is not shown in SMTP mail client (C# .NET)

I’m using Aspose.Email for .net version 19.2

I need to send email messages using the SmtpClient.
The email is created using the MailMessage object.
No matter what i do, the display name is not shown in email clients (Outlook, Outlook Online, Gmail)

Test using MailAddress

    MailAddress fromAddress = new MailAddress("apptest@test.com","John Smith");
    MailAddress toAddress = new MailAddress("test@test.com");
    MailMessage mm = new MailMessage(fromAddress,toAddress);
    mm.Subject = "test subject";
    mm.Body = "test body";

Test using MailMessage.From with a display name

    MailMessage mm = new MailMessage();
    mm.From = "John Smith <apptest@test.com>";
    mm.To = "test@test.com";
    mm.Subject = "test subject";
    mm.Body = "test body";

What do i need to do in order to show “John Smith” as display name in a email client?

Note: This is not a problem of the mail client, but the display name is not even part of the raw message source:
It just uses the first part of the email address as display name

Message source for the above email

 From: apptest <apptest@test.com>
To: "test@test.com" <test@test.com>
Subject: test subject
Thread-Topic: test subject

@manuelk

I have worked over your requirements and have created following example on my end.

public static void TestSMTP()
{
    try
    {

        string mailboxUri = "https://exchange.aspose.com/ews/exchange.asmx";
        //   string username = "asposeemail.test3@aspose.com";
        string username = "asposeemail.test3@aspose.com";
       
        string tousername = "xxxx.xxxx@gmail.com";
       

        string password = "password";

        MailAddress fromAddress = new MailAddress(username, "Mudassir 3");
        MailAddress toAddress = new MailAddress(tousername, "Mudassir 123");
        MailMessage mm = new MailMessage(fromAddress, toAddress);


        mm.From = fromAddress;
        mm.To = toAddress;
        mm.Subject = "test subject";
        mm.Body = "test body";

        // Create an instance of the SmtpClient class
        SmtpClient client = new SmtpClient();


        // And Specify your mailing host server, Username, Password and Port
        client.Host = "exchange.aspose.com";
        client.Username = username;
        client.Password = password;
           
        //Client.Send will send this message
        client.Send(mm);
        Console.WriteLine("Message sent");
        }
        catch (Exception e)
        {
            String s = e.StackTrace;
        }
        

}

Please observe the view of email being received in Gmail and showing the sender name rather than email. I don’t feel this is issue related to Aspose.Email.

Still doesn’t work on my side. I just copied your code and changed the address:

                string username = "apptest@foo.com";
                string tousername = "test@gmail.com";

                MailAddress fromAddress = new MailAddress(username, "Mudassir 3");
                MailAddress toAddress = new MailAddress(tousername, "Mudassir 123");
                MailMessage mm = new MailMessage(fromAddress, toAddress);

                mm.From = fromAddress;
                mm.To = toAddress;
                mm.Subject = "test subject";
                mm.Body = "test body";

                SmtpClient smtpClient = new SmtpClient("outlook.office365.com", 587, SecurityOptions.SSLAuto);
                smtpClient.Username = "apptest@foo.com";
                smtpClient.Password = "password";

                smtpClient.Send(mm);

In gmail, it is shown like this:
image.png (9.4 KB)

And if i check the original message in gmail, it shows that the To-Name was set properly, but the From-Name is ignored:
image.png (32.5 KB)

Which version of aspose are you using?

I have done some more testing:
When using a google account for sending the email, the name in the email is shown as expected.

SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);

But if i use a microsoft office365 account, it doesn’t work.

SmtpClient smtpClient = new SmtpClient("outlook.office365.com", 587 );

I’ll check with our AD admin whether this can be configured on the account

@manuelk,

If it had been an issue with API then Gmail would have been reproducing the same issue. I think you may need to verify the configuration on your end.