MailMessage to send emails will raise the following errors “Mailbox unavailable” + “Error in process

Highlighted
Valued Contributor

I have the following code inside my asp.net console application to send an email using office 365 smtp server:-

 

 

static private void sendemail(ClientContext context, string subject, string body, string to)
        {
            using (MailMessage mail = new MailMessage())
            {
                mail.From = new MailAddress("sharepoint@outorganization.com");
                mail.Subject = subject;
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "ourorganization-com.mail.protection.outlook.com";
                smtp.EnableSsl = true;
                mail.Body = body;
                mail.To.Add("***@****.net");   
                smtp.Port = 25;
                smtp.Send(mail);
            }

        } 

static void Main(string[] args)
        {
            string s = "******";
            SecureString passWord = new SecureString();
            foreach (var cc in s)
                passWord.AppendChar(cc);
            using (ClientContext context = new ClientContext("https://****.sharepoint.com/"))

            {

                context.Credentials = new SharePointOnlineCredentials("***@***.onmicrosoft.com", passWord);
                sendemail(context,"test 123","test123 body","***@***.net");

            }
        }

 

 

 

but the smtp.Send(mail); is raising the following errors, i got different errors depending on the server i am running the above code in:-

 

Error-1

Mailbox unavailable. The server response was: 5.7.1 Service unavailable, Client host [165.225.80.126] blocked using Spamhaus. To request removal from this list see https://www.spamhaus.org/query/ip/165.225.80.126 AS(1450) [VE1EUR01FT009.eop-EUR01.prod.protection.outlook.com]

Error-2

System.Net.Mail.SmtpException: 'Error in processing. The server response was: 4.4.62 Mail sent to the wrong Office 365 region. ATTR35. For more information please go to https://go.microsoft.com/fwlink/?linkid=865268 [HE1EUR01FT009.eop-EUR01.prod.protection.outlook.com]'

 so can any one advice on this please? keeping in mind that i used the same code and it worked well on another office 365 tenant.

0 Replies