SQL Mail Account Name not displaying properly while sending mail from ASP.NET Application

BeUnique 2,112 Reputation points
2024-06-23T15:57:21.8333333+00:00

I am developing ASP.NET web application.

In that, i am sending mail to end user from my SQL Mail profile.

i have the below mail profile and account name and mail id.

SQL Mail Account Name : IND GROUP MAIL

E-mail ID : indteamsupport@jeevesteam.com

We are sending mail from "indteamsupport@jeevesteam.com", but, SQL Mail Account name "IND GROUP MAIL" not displaying in the from account.

It should come like below to end user.

From : IND TEAM MAIL indteamsupport@jeevesteam.com

To : xxxxxxx

End user getting mail without "IND GROUP MAIL" this. .....?

below is the ASP.NET (C#) code for sending mail to end user.


using System;

using MailKit.Net.Smtp;
using MailKit;
using MimeKit;

namespace TestClient {
  class Program
  {
    public static void Main (string[] args)
    {
      var email = new MimeMessage();

      email.From.Add(new MailboxAddress("Sender Name", "IND TEAM MAIL <indteamsupport@jeevesteam.com>"));
      email.To.Add(new MailboxAddress("Receiver Name", "xyz@email.com"));

      email.Subject = "Testing out email sending";
     email.Body = new TextPart(MimeKit.Text.TextFormat.Plain) { 
    Text = "Hello all the way from the land of C#"
};
      using (var smtp = new SmtpClient())
      {
        smtp.Connect("smtp.server.address", 587, false);

        // Note: only needed if the SMTP server requires authentication
        smtp.Authenticate("smtp_username", "smtp_password");

        smtp.Send(email);
        smtp.Disconnect(true);
      }
    }
  }
}
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,415 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,640 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 28,841 Reputation points Microsoft Vendor
    2024-06-24T07:30:58.62+00:00

    Hi @Gani_tpt,

    There is a problem with the following line of code.

    User's image

    Correct way to write it:

    email.From.Add(new MailboxAddress("IND TEAM MAIL ", "indteamsupport@jeevesteam.com"));
    

    User's image

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Erland Sommarskog 107K Reputation points
    2024-06-23T17:32:14.0766667+00:00

    SQL Mail? You are not using SQL Mail. You are using the MimeKit and MailKit classes developed by Jeffrey Stedfast, with the documentation found here: https://mimekit.net/docs/html/Introduction.htm (And which I had never heard of prior to seeing your post.) There is zero relation to SQL Mail.

    Looking at his Getting Started examples, it seems that you are calling the MailboxAddress constructor in the wrong way. I think you should have:

       email.From.Add(new MailboxAddress("IND TEAM MAIL", "indteamsupport@jeevesteam.com"));
    
    1 person found this answer helpful.
    0 comments No comments