使用Exchange服务器在asp.net中发送邮件(smtp:outlook.office365.com) [英] Sending Mail in asp.net using Exchange server(smtp:outlook.office365.com)
问题描述
我们在asp.net的邮件系统中工作,我们的客户端使用的是Microsoft Exchange服务器outlook.office365。我们得到System.Net.Mail.SmtpException:操作超时错误。我谷歌所有来源,但没有为我工作。请帮助我们。提前致谢。
btn_click(){
try {SmtpClient smtp = new SmtpClient(smtp .outlook.office365.com);
smtp.Host =outlook.office365.com;
smtp.Port = System.Convert.ToInt32(443);
System.Net.NetworkCredential cred = new System.Net.NetworkCredential(userid,mypwd);
smtp.Credentials = cred;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.TargetName =STARTTLS / outlook.office365.com;
MailMessage msg = new MailMessage();
msg.From = new MailAddress(frommailid ,username);
msg.To.Add(new MailAddress(xxx@xxx.com));
msg.Subject =测试;
msg.Body =测试邮件;
smtp.Timeout = 60000;
smtp.Send(msg);
} catch(例外情况)
{
抛出ex;
}
}
MailMessage msg = new MailMessage();
msg.To .Add(新邮件地址(someone@somedomain.com,SomeOne));
msg.From =新邮件地址(you@yourdomain.com,你);
msg.Subject =这是一个测试邮件;
msg.Body =这是使用Exchange OnLine的测试消息;
msg .IsBodyHtml = true;
SmtpClient客户端=新的SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(您的用户名,您的密码);
client.Port = 587; //如果587被阻止你可以使用端口25(我的是!)
client.Host =smtp.office365.com;
client.DeliveryMethod = SmtpDeliveryMethod。网络;
client.EnableSsl = true;
尝试
{
client.Send(msg);
lblText.Text =消息已成功发送;
}
catch(例外情况)
{
lblText.Text = ex.ToString();
}
System.Net.Mail.MailMessage message = new System.Net。 Mail.MailMessage();
//从注册表中读取电子邮件
string fromEmail = Registery.fromAddress;
//从注册表中读取密码
string fromPassword = Registery.password;
//读取地址来自registery
string toAddress = Registery.ToAddre ss;
//从注册表中读取外发服务器名称
string smtpServer = Registery.smtpServer;
//从注册表中读取传出服务器的端口
int port = Convert.ToInt32(Registery.port);
//读取来自registery的enableSSL是true还是false
bool enableSSL = Convert.ToBoolean(Registery.enableSSL);
条消息.From = new MailAddress(fromEmail.ToString());
message.To.Add(toAddress.ToString());
message.Subject = ServiceName + + status.ToString();
message.Body =服务名称:+ ServiceName + Environment.NewLine +状态:+ status.ToString();
message.IsBodyHtml = true;
message.DeliveryNotificationOptions = DeliveryNotificatio nOptions.OnFailure;
/// smtp在注册表配置的服务器和端口
SmtpClient smtpClient = new SmtpClient(smtpServer,port);
///启用安全连接需要ssl。对于gmail服务器必须为true,对其他服务器必须为false。
smtpClient。 EnableSsl = enableSSL;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(fromEmail,fromPassword);
smtpClient.Send(message);
}
catch(例外情况)
{
Logger.Log(发送邮件时出错。 + ex.Message +,+ ex.InnerException,3);
}
smtp.gmail.com和587 for gmail .... .....
Hi,
We are working in Mailing system in asp.net,our client using Microsoft exchange server outlook.office365 . we are getting "System.Net.Mail.SmtpException: The operation has timed out error ". i google all sources but didn't work for me.Please help us. Thanks in advance.
btn_click(){
try{SmtpClient smtp = new SmtpClient("smtp.outlook.office365.com");
smtp.Host = "outlook.office365.com";
smtp.Port = System.Convert.ToInt32("443");
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("userid", "mypwd");
smtp.Credentials = cred;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.TargetName = "STARTTLS/outlook.office365.com";
MailMessage msg = new MailMessage();
msg.From = new MailAddress("frommailid", "username");
msg.To.Add(new MailAddress("xxx@xxx.com"));
msg.Subject = "Test";
msg.Body = "Test mail ";
smtp.Timeout = 60000;
smtp.Send(msg);
}catch(exception ex)
{
throw ex;
}
}
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("someone@somedomain.com", "SomeOne"));
msg.From = new MailAddress("you@yourdomain.com", "You");
msg.Subject = "This is a Test Mail";
msg.Body = "This is a test message using Exchange OnLine";
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("your user name", "your password");
client.Port = 587; // You can use Port 25 if 587 is blocked (mine is!)
client.Host = "smtp.office365.com";
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
try
{
client.Send(msg);
lblText.Text = "Message Sent Succesfully";
}
catch (Exception ex)
{
lblText.Text = ex.ToString();
}
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
//Read fromEmail from registery
string fromEmail = Registery.fromAddress;
//Read fromPassword from registery
string fromPassword = Registery.password;
//Read toAddress from registery
string toAddress = Registery.ToAddress;
//Read outgoing server name from registery
string smtpServer = Registery.smtpServer;
//Read port of outgoing server from registery
int port = Convert.ToInt32(Registery.port);
//Read whether enableSSL is true or false from registery
bool enableSSL = Convert.ToBoolean(Registery.enableSSL);
message.From = new MailAddress(fromEmail.ToString());
message.To.Add(toAddress.ToString());
message.Subject = ServiceName + " " + status.ToString();
message.Body = "Service Name :" + ServiceName + Environment.NewLine + "Status :" + status.ToString();
message.IsBodyHtml = true;
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
///smtp server and port configured at registry
SmtpClient smtpClient = new SmtpClient(smtpServer, port);
///enable ssl is required for secure connection.It is must be true for gmail server and false for other servers.
smtpClient.EnableSsl = enableSSL;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(fromEmail,fromPassword);
smtpClient.Send(message);
}
catch (Exception ex)
{
Logger.Log("Error In Sending Mail. " + ex.Message + " , " + ex.InnerException, 3);
}
smtp.gmail.com and 587 for gmail .........
这篇关于使用Exchange服务器在asp.net中发送邮件(smtp:outlook.office365.com)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!