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

Steel Contributor

I have the following code inside my 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("");
                mail.Subject = subject;
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "";
                smtp.EnableSsl = true;
                mail.Body = body;
                smtp.Port = 25;


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


                context.Credentials = new SharePointOnlineCredentials("***@***", 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:-



Mailbox unavailable. The server response was: 5.7.1 Service unavailable, Client host [] blocked using Spamhaus. To request removal from this list see AS(1450) []


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 []'

 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