Click here to Skip to main content
14,931,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
MailMessage mail = new MailMessage();

        mail.From = new MailAddress(txtEmail.Text.Trim());
        mail.To.Add("sshalemo@ad-betparkingservice.com");

        mail.Subject = txtSubject.Text.Trim();
        mail.IsBodyHtml = true;
        mail.Body = GetBody();

        

        //send the message
        SmtpClient smtpClient = new SmtpClient();
        smtpClient.Host = "smtpout.secureserver.net";//smtpout.secureserver.net relay-hosting.secureserver.net
        smtpClient.Port = 587;
        smtpClient.EnableSsl = true;
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials =
                  new NetworkCredential("sshalemo@ad-betparkingservice.com", "password");

        
        smtpClient.Timeout = 20000;
        smtpClient.Send(mail);


Please help me
Posted
Updated 20-Jun-19 19:16pm
v2

try this host

smtpClient.Host = "smtp.office365.com";
   
Hello, since you're using the ASP.NET technology, don't waste time doing C# base things. ASP.NET was developed over .NET Framework to help you write less C# code and do more on the Internet.

You can use the ASP.NET codes to send the emails using any email service provider to any recipient on the internet. You can just use the username and password that you get from the email service provider. Basic example of this provider is Google Mail (Gmail) or Outlook, you can use any of them and just pass the username and password of yours to the ASP.NET (along with some more parameters and properties) and your email will be sent using one line code.

The code is really very simple, I have already covered this in the Article,

Sending emails easily using ASP.NET helpers[^]

Feel free to read it, and you will learn how to send the emails using ASP.NET C# code. It is really very helpfull and easy to send the emails using ASP.NET WebMail class instead of using the old C# email sender.
   
Comments
Shahnawazcode 23-Aug-14 3:05am
   
this code is perfect for me for other server. but when i try to use it in godaddy outlook 365 mail server it show error. If I use your code it also give me the error. if you are working with this server please give me the smtp address and port number? I think this is the problem
thanks
Afzaal Ahmad Zeeshan 23-Aug-14 9:37am
   
Then change the port number and also tell the exception that you're getting (the error message) the error message to be told is the essential part, since you will get the desired answer only when the helper is getting the desired data in the question.
Shahnawazcode 23-Aug-14 11:45am
   
I update the code I found from online is like:
http://www.limilabs.com/blog/outlook365-imap-pop3-smtp-settings

but it gives me error:
System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Afzaal Ahmad Zeeshan 23-Aug-14 13:20pm
   
The only solution for this is provided in my article too. The error states that you are not providing any security. In the Article, look for the WebMail.EnableSsl = true; part, that is the part required by every email provider. They won't allow you to send an unsecure email. Enable SSL and you'll be up and running. As I already told you, just go through my article, it explains the basics well.
Shahnawazcode 24-Aug-14 2:19am
   
I am using this example but it still same error:
http://itzonesl.blogspot.com/2013/04/send-email-through-office-365-outlook.html

System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900