Send Email using Exchange Server - email

I have an exchange account. I need to send an email with it. I tried sending with SmtpClient and it fails. I have few questions after googling
What are the things needed to send email with an exchange account?
What's difference between WebDav and MAPI? Which should be used?
Any Ideas?
Here is my code. I think this can't be done with SMTP.
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("sender#domain.com", "Sender");
mailMessage.To.Add("receiver#domain.com");
mailMessage.Subject = "Test Exchange Email";
mailMessage.Body = "Sameple test message";
SmtpClient smtp = new SmtpClient("Exchange Server Url");
smtp.EnableSsl = true;
smtp.Port = 465;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("username", "pwd");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(mailMessage);

Related

How to send mail based on from email address using smtp c#

We want to send email using from email address instead of smtp email address...
I tried to send mail where from email address and smtp authenticated email address are different.
It gives me error.
You can based on the following code below. Hope it helps
MailMessage mailMessage = new MailMessage();
mailMessage.IsBodyHtml = true;
mailMessage.From = new MailAddress("sender#domain.com", "Subject"); // You can try changing this to the email address you want
mailMessage.ReplyToList.Add("sender#domain.com"); // Here you can add reply to
mailMessage.Subject = "ENQUIRY - " + DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss");
mailMessage.Body = ""; // The body of email
SmtpClient smtpClient = new SmtpClient("mail.company-domain.com");
smtpClient.Credentials = new NetworkCredential("username", "password");
smtpClient.Port = 587; // We used this port instead of port 25
smtpClient.Send(mailMessage);

Cannot send mail from an Azure VM using Gmail

I am trying to send Email from an asp.net webform using Gmail.
the code works from my machine but when I upload the code to my windows server 2012 in Azure I get
Unable to connect to Remote Server - exception
here is my code:
MailMessage mail = new MailMessage();
mail.Subject = "Subject";
mail.Body = "Main body goes here";
mail.From = new MailAddress("myAcount#gmail.com");
mail.IsBodyHtml = true;
mail.BodyEncoding = System.Text.Encoding.Unicode;
mail.SubjectEncoding = System.Text.Encoding.Unicode;
mail.To.Add("aaaa#gmail.com");
NetworkCredential cred = new NetworkCredential("myAccount#gmail.com", "myPwd");
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.EnableSsl = true;
smtp.Credentials = cred;
smtp.Port = 587;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(mail);
Any ideas?
Make sure the local VM's Firewall rules are permitting outgoing connection via port 587. Here is a good article on how to create outbound Firewall rule.

Classic ASP emails not working with Outlook SMTP relay

I am trying to get the classic ASP page working with Outlook (Microsoft Web Email) SMTP relay. I am getting the following error :
CDO.Message.1 error '80040213'
The transport failed to connect to the server.
My code looks like
dim objEmail
Set objEmail = Server.CreateObject("cdo.message")
objEmail.To = list
objEmail.From = "xyz#abc.com"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServer
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = username
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = password
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
objEmail.Configuration.Fields.Update
objEmail.Send
I tested with GMAIL and this thing snippet works fine with it. I guess I am missing something in configuration of Outlook SMTP
Here is an example that does work. Make sure that the account you use has a mailbox, and the from adress is indeed the account adress.
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
var msg = new MailMessage();
msg.Subject = "Hello";
msg.Body = "Hello Sir";
msg.From = new MailAddress("no.reply#contoso.com");
msg.To.Add("user#contoso.com");
var client = new SmtpClient("smtp.outlook.office365.com");
client.Port = 587;
client.Credentials = new NetworkCredential("no.reply#contoso.com", "******");
client.EnableSsl = true;
client.Send(msg);

Is there any possibility to send a mail in sharepoint 2010 using gmail smtp configuration

Is there any possibility to send a mail in sharepoint 2010 using gmail smtp configuration.
I tried using .net.It is successfully going.. But i need this in sharepoint 2010 without usind SMTP configuration in Central administration in sharepoint 2010
I tried it by using event handler, but i can't
thanks in advance.....
//SmtpClient serverobj = new SmtpClient();
//serverobj.UseDefaultCredentials = true;
//serverobj.Credentials = new NetworkCredential("xxx#gmail.com", "Password");
//serverobj.Port = 587;
//serverobj.Host = "Smtp.gmail.com";
//serverobj.EnableSsl = true;
//MailMessage msgobj = new MailMessage();
//msgobj.From = new MailAddress("xxx#gmail.com", Subject ", System.Text.Encoding.UTF8);
//msgobj.To.Add("yyy#gmail.com.com");
//msgobj.Subject = "New Application Request";
//msgobj.Body = "Hi this is test mail";
//serverobj.Send(msgobj);

Unable to send mail in Silverlight

I wrote a WCF service for sending mail in Silverlight:
using System.Web.Mail;
MailMessage msg = new MailMessage();
msg.From = emailFrom;
msg.To = emailTo;
msg.Subject = msgSubject;
msg.Body = msgBody;
msg.Priority = MailPriority.High;
SmtpMail.Send(msg);
success = true;
This works fine in localhost, but when I host it in IIS, it doesn't show any error, but no mail has been received. What may be the problem?
Try to set the smtpserver property for the smtpmail class before you call the send method.