I am trying to send an e-mail using a c# program I wrote to a destination company address managed by Microsoft; by default it uses my company address to send it, but I don't want my address to appear as then sender, I have tried using the "On behalf of " option, but that still shows both addresses as sender. Is there a way to change the sender without having to configure that specific sender account in my computer. I think it might not be possible because the SMTP would block the e-mail because of it being spoofed, but I hope there is a way around it. In case that's not possible is there a way to enter that e-mail credentials and SMTP server information into the C# code so I don't have to actually setup Outlook on the machine that will be sending the e-mails? Thanks in advance for the help.
Changing source e-mail address from C# program using Microsoft.Office.Interop.Outlook
959 Views Asked by FelipeGuerra At
2
There are 2 best solutions below
1

You can use the System.Net.Mail namespace for this. You can send from any address you want.
using System.Net;
using System.Net.Mail;
using (SmtpClient client = new SmtpClient("yourserver"))
{
client.Credential = new NetworkCredential();
MailMessage message = new MailMessage();
message.To.Add("targetAddress");
message.From = new MailAddress("from addresss");
message.Subject = "blah blah";
message.Body = "body text. this can be html if you want";
message.IsBodyHtml = true; //set this to true if the body is html
client.Send(message);
}
I've used this with Microsoft exchange and gmail and never had any trouble.
http://www.dotnetlearners.com/blogs/view/80/SMTP-send-email-source-code.aspx