我有一个asp.net
Web表单,单击按钮即可发送,我希望将电子邮件发送到我的Microsoft Outlook电子邮件帐户。我在其他方面做到了
网站,但使用的是hotmail,但所有外部Web电子邮件提供商均被公司防火墙阻止(因为我尝试设置gmail帐户),因此
我需要使用Outlook,但我不知道如何实施该解决方案,而我在Google上看到的解决方案似乎也不起作用。我不知道它会不会
差异与否,但我已经得知用户密码每30天出现一次,因此我怀疑我需要使用Windows身份验证或其他功能
但不确定。
我不确定Outlook如何发送电子邮件,如我从使用hotmail的以往经验中所知道的那样,仅在单击按钮后才发送电子邮件,但是我
不知道Outlook是否会打开电子邮件窗口供用户单击“发送”按钮。如果是这样,我需要在网络表单上捕获的信息是
电子邮件中包含的内容以及电子邮件正文的内容均不得更改(如果可以这样做,请再次确认是否可以更改,但不能确定是否存在问题)
不能)。
下面是我尝试gmail时使用的代码,但正如我所说,我被告知不允许这样做。
using System.Configuration;
using System.Net.Mail;
using System.Net;
using System.IO;
protected void BtnSuggestPlace_Click(object sender, EventArgs e)
{
#region Email
try
{
//Creates the email object to be sent
MailMessage msg = new MailMessage();
//Adds your email address to the recipients
msg.To.Add("[email protected]");
//Configures the address you are sending the email from
MailAddress address = new MailAddress("[email protected]");
msg.From = address;
//Allows HTML to be used when setting up the email body
msg.IsBodyHtml = true;
//Email subjects title
msg.Subject = "Place Suggestion";
msg.Body = "<b>" + lblPlace.Text + "</b>" + " " + fldPlace.Text
+ Environment.NewLine.ToString() +
"<b>" + lblLocation.Text + "</b>" + " " + fldLocation.Text
+ Environment.NewLine.ToString() +
"<b>" + lblName.Text + "</b>" + " " + fldName.Text;
//Configures the SmtpClient to send the mail
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.EnableSsl = true; //only enable this if the provider requires it
//Setup credentials to login to the sender email address ("UserName", "Password")
NetworkCredential credentials = new NetworkCredential("[email protected]", "MyPassword");
client.Credentials = credentials;
//Send the email
client.Send(msg);
}
catch
{
//Lets the user know if the email has failed
lblNotSent.Text = "<div class=\"row\">" + "<div class=\"col-sm-12\">" + "There was a problem sending your suggestion. Please try again."
+ "</div>" + "</div>" + "<div class=\"form-group\">" + "<div class=\"col-sm-12\">" + "If the error persists, please contact Antony." + "</div>" +
"</div>";
}
#endregion
}
编辑2:现在我们已经确定了您的工作经历,这就是我的代码始终有效的方式
SmtpClient sptmClient = new SmtpClient("exchange server name")
MailMessage m = new MailMessage();
m.To.Add(new MailAddress("Address"));
m.From = new MailAddress("");
m.Subject = "";
m.Body = "";
m.IsBodyHtml = true;
sptmClient.Send(m);
但是这里还有另一个答案,那就是使用Outlook互操作可能更适合您
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句