Manish Solanki

Manish Solanki

  • NA
  • 77
  • 25.5k

to send mail in office outlook using

Oct 14 2015 5:18 AM
Hello Everyone
   I have send mail office outlook.
I was get this error: System.Net.Mail.SmtpException: The operation has timed out.
 Please help me solve it.
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.Text;
public partial class Default12 : System.Web.UI.Page
{
public class OutlookDotComMail
{
string _sender = "";
string _password = "";
string _domain = "";
public OutlookDotComMail(string sender, string password)
{
_sender = sender;
_password = password;
}
public void SendMail(string recipient, string subject, string message)
{
SmtpClient client = new SmtpClient();
client.Host = "mail.globaltechnopartners.com";
client.Port = 465;
client.UseDefaultCredentials = false;
// client.DeliveryMethod = SmtpDeliveryMethod.Network;
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential(_sender, _password, _domain);
var creds = CredentialCache.DefaultCredentials;
client.EnableSsl = true;
client.Credentials = credentials;
try
{
var mail = new MailMessage(_sender.Trim(), recipient.Trim());
mail.Subject = subject;
mail.Body = message;
client.Send(mail);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
}
internal void SendMail(string email)
{
throw new NotImplementedException();
}
}
protected void Page_Load(object sender, EventArgs e)
{
string mailuser = "[email protected]";
string mailuserpass = "*******";
var sender1 = new OutlookDotComMail(mailuser, mailuserpass);
sender1.SendMail("[email protected]", "sign in", "Demo");
}
}
 

Answers (4)