在没有网络凭据的情况下以C#发送电子邮件 [英] sending email in c# without network credential
本文介绍了在没有网络凭据的情况下以C#发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,专家,
我正在尝试创建一个类,该类将公开带有输入参数To,From,Subject和电子邮件内容的发送电子邮件功能.
我想使用大多数Windows登录时间的Outlook凭据执行此操作.
发送电子邮件时如何使用Outlook凭据/Windows凭据.
我正在尝试的代码片段如下:
Hi Experts,
I am trying to create a class that will expose send email functionality with input params To,From,Subject and email content.
i want to perform this action with outlook credential that is most of the time windows login.
how can i use outlook credential/windows credential while sending an email.
code snipped i am trying is as follows:
SmtpClient client = new SmtpClient();
MailMessage msg = new MailMessage();
System.Net.NetworkCredential smtpCredential = new System.Net.NetworkCredential("tasu007@gmail.com", "");
client.Host = "smtp.gmail.com";
client.Port = 587;;
client.UseDefaultCredentials = false;
client.Credentials = smtpCredential;
client.EnableSsl = true;
MailAddress from = new MailAddress("tasu007@gmail.com");
MailAddress to = new MailAddress("tasu007@gmail.com");
msg.Subject = "test email";
msg.Body = "Hello Info";
msg.From = from;
msg.To.Add(to);
try
{
client.Send(msg);
}
catch (Exception ex)
{
}
推荐答案
如果要使用Outlook发送邮件,请使用 ^ ]
If you want to send mail using Outlook then use the Outlook Interop[^]
马克,
我不想使用Outlook发送电子邮件..我只想使用已提供给Outlook的网络凭据.
希望这次我能说清楚.
问候,
维卡斯(Vikas)
Hi Mark,
i do not want to use outlook to send an email..i just want to use network credential that has been supplied to outlook.
Hope i make it clear this time.
Regards,
Vikas
这篇关于在没有网络凭据的情况下以C#发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文