1

I must send different emails... Every email has a aits own sender.. I want to connect to my smtp server just with one account..

So, for example I want to connect to the smtp server with this user: smtpclient@something.com

But I want to send the email from noreply@something.com

I wrote some code that send the email.. the code works because I receive the email.. but something goes wrong: I receive the email from smtpclient@something.com but I would like to receive the email from noreply@something.com

I am using EmailDefinition:

MailDefinition mailDefinition = new MailDefinition();
mailDefinition.BodyFileName = urlEmailLayout;
mailDefinition.IsBodyHtml = true;
mailDefinition.From = from.EmailAddress;

MailMessage email = mailDefinition.CreateMailMessage(string.Join(",", to.Select(t => t.EmailAddress)), bodyValues, new System.Web.UI.LiteralControl());
email.From = new MailAddress(from.EmailAddress, from.DisplayName);

And to send the email I use SmtpClient:

SmtpClient client = new SmtpClient(smtpServer.Host, smtpServer.Port);
client.EnableSsl = smtpServer.RequireCredential;

if(smtpServer.RequireCredential)
    client.Credentials = 
        new System.Net.NetworkCredential(
                smtpServer.Credential.Username, 
                smtpServer.Credential.Password
        );

client.Send(this._email);

How can I do?

Thanx

Simone
  • 2,304
  • 6
  • 30
  • 79

1 Answers1

0

I don't think it works like that. Whatever credentials you use for your SMTP connection is the address it gets sent from.

Why not just connect to the SMPT server using the credentials for noreply@something.com?

KDizzle
  • 51
  • 6
  • I have different kind of email... and every type of email has a different sender... It would mean that eveytime I must send an email I must connect with a different user... I would like to avoid this and use always one user to connect... I honestly think that what you say has sense.. I think the same thing.. but on the other side, it look like strange to me that is not possible have more flexibility... – Simone Apr 10 '15 at 11:02
  • 1
    You can definitely do this, did it before, but it might be a configuration on the mail server to allow it. – Angelo Reis Apr 10 '15 at 11:02
  • Have a look at this link. Expand the sections and see if any of these options are suitable for you, that is if you're using gmail. https://support.google.com/mail/answer/22370?hl=en – KDizzle Apr 10 '15 at 11:10
  • I am using a my own smtp server – Simone Apr 10 '15 at 11:33