0 votes
by (120 points)
edited by

Hi,

I am trying to send email using rcpt to. I had set from address(from@domain.com) but at the receiver and it show actual email address (auth@domain.com). Can you please help me to solve this problem? Here is my code.

Smtp smtp = new Smtp();
smtp.Connect("smtp.gmail.com", SslMode.Explicit);
smtp.Login("auth@domain.com", password, SmtpAuthentication.Login);                

string mailFrom = "from@domain.com";
string rcptTo = "rcptTo@domain.com";
string mailTo = "to@domain.com";

MailMessage mail = new MailMessage();
mail.To = mailTo;
mail.From = mailFrom;
mail.Headers.Add("From", mailFrom);
mail.Subject = "Hello Freddy, this is your friend Peter sending you a test email";
mail.BodyText = "Hello Freddy, this is the body text";

//smtp.Send(mail);
smtp.Send(mail, mailFrom, rcptTo);

I tried with sample that I got from the website. But I still got same error. It behave same for both Send method.

Applies to: Rebex Secure Mail

1 Answer

0 votes
by (72.7k points)

This seems to be a specific of Gmail SMTP server.

I have 3 hints:

  1. Do not call mail.Headers.Add("From", mailFrom); by calling this, you added another From header to the message. Maybe, this can cause troubles with GMail.

  2. Try to set mail.Sender as well. It can be done like this:

    MailMessage mail = new MailMessage();
    mail.From = mailFrom;
    mail.Sender = mailFrom;

  3. Try to look into Gmail settings. I think that the accounts of the two users "auth" and "from" should be linked somehow. And the "auth" user should have permission to send mails on behalf of "from" user.

by (120 points)
Thanks Lukas
I have tried with mail.Sender property. But I got same result.
I have removed header as  you suggest me. The emails are not linked. I have permission to send mail. I can get desire result with System.Net.Mail.Smtp.
by (72.7k points)
Can you please share with us the code you used for System.Net.Mail.Smtp?
You can send it to support@rebex.net
If system Smtp class is able to make this working, we should be able to do it as well.
...