开发者

Changing the Sender's email address and name when sending an email using an Outlook object in C#

开发者 https://www.devze.com 2023-04-10 16:55 出处:网络
I have been trying开发者_JS百科 to figure this one out for the last 2 days. I feel like I\'m really close, but just can\'t get it. I\'ve gotten my c# program to successfully send an email with all the

I have been trying开发者_JS百科 to figure this one out for the last 2 days. I feel like I'm really close, but just can't get it. I've gotten my c# program to successfully send an email with all the required information in it, but I can't change the sender's name and email address. Here is my code so far:

Outlook.Application oApp = new Outlook.Application();

string emailrecipient = (Convert.ToString(txtAdmin1.Text) + "@domain.com");


            Outlook.MailItem email = (Outlook.MailItem)(oApp.CreateItem(Outlook.OlItemType.olMailItem));
            email.Recipients.Add(emailrecipient);
            email.Subject = "Your Recent Admin Rights Request";
            email.Body = "Your admin rights request has been processed. The user " + txtAdmin1.Text + " has been added as an administrator on computer " + txtName.Text + ". Please reboot your computer for these changes to take effect.";

            email.Send();

any advice would be amazing. I've searched all over the place, and haven't found anything that has worked so far.


I do believe that because you are using the Outlook object model, the From property is read only (i think its called SenderName / SenderEmailAddress).

Outlook runs in the context of a specific user, so to change the user you would have to login to outlook using different credentials.


Better change the profile name from server if you are using Interop.Outlook.dll

0

精彩评论

暂无评论...
验证码 换一张
取 消