[英]Sending email on behalf of other user for office365-outlook
I am sending an email using a console application created using C#.I want to send this email with a different From name
, I have found the same code on many sites, but it is not working in my case. 我正在使用使用C#创建的控制台应用程序发送电子邮件。我想使用不同的
From name
发送该电子邮件,我在许多站点上都找到了相同的代码,但在我的情况下不起作用。
MailAddress mailFrom = new MailAddress("xyz@abc.com", "Sender");
I am using office365- outlook. 我正在使用office365- Outlook。
My complete code is:- 我完整的代码是:
SmtpClient SmtpServer = new SmtpClient("smtp.office365.com", 25);
MailAddress mailFrom = new MailAddress("xyz@abc.com", "Mailer");
MailAddress mailTo = new MailAddress("xyz@abc.com");
MailMessage mail = new MailMessage(mailFrom, mailTo);
mailt.Subject = "Test Mail";
mailt.Body = "This is for testing";
SmtpServer.Credentials = new System.Net.NetworkCredential("xyz@abc.com", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
So in this case is it possible to change the sender name for sending email or can we send email on behalf of other user in outlook using code? 因此,在这种情况下,可以更改发送电子邮件的发件人名称,还是我们可以使用代码代表Outlook中的其他用户发送电子邮件?
Using the Outlook
object model , you can do: 使用
Outlook
对象模型 ,您可以执行以下操作:
Outlook.Application OL = ....;
Outlook._MailItem mail;
mail = OL.CreateItem(Outlook.OlItemType.olMailItem) as Outlook._MailItem;
mail.Subject = subject;
mail.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
mail.HTMLBody = body;
// add recipients
// ....
mail.SentOnBehalfOfName = sender;
mail.Send();
This requires Outlook
to be installed on your system. 这要求在系统上安装
Outlook
。
To get hints about what could be wrong with your code, you should describe the error messages or failure you are getting. 为了获得有关代码可能出问题的提示,您应该描述错误消息或遇到的故障。
你可以做:
mail.From = new MailAddress("test@example.com");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.