Gmail SMTP blocks Office documents but allows images - How to fix?

I’m having trouble sending Office files like Excel and Word documents through Gmail SMTP. Image files and text files work fine but document files get blocked. Has anyone faced this issue before?

private void CreateAndSendEmail(string recipient, string copyTo, string emailSubject, string messageContent)
{
    // Create email message
    MailAddress toAddr = new MailAddress(recipient);
    MailAddress fromAddr = new MailAddress("[email protected]");
    MailMessage message = new MailMessage(fromAddr, toAddr);
    
    message.Subject = emailSubject;
    message.Body = messageContent;
    message.CC.Add(new MailAddress(copyTo));
    
    AttachFiles(message);
    message.IsBodyHtml = true;
    message.BodyEncoding = Encoding.UTF8;
    
    DeliverEmail(message);
}

private void AttachFiles(MailMessage message)
{
    foreach (string filePath in attachmentList)
    {
        Attachment fileAttachment = new Attachment(filePath);
        message.Attachments.Add(fileAttachment);
    }
}

private void DeliverEmail(MailMessage message)
{
    try
    {
        SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
        client.EnableSsl = true;
        client.UseDefaultCredentials = false;
        client.Credentials = new NetworkCredential("[email protected]", "password");
        client.Send(message);
    }
    catch (Exception error)
    {
        MessageBox.Show(error.Message);
    }
}

Any alternative methods to send these file types would be helpful too.

Gmail SMTP blocks executable files and certain document formats - it’s not your code, it’s their security filtering. I’ve hit this wall tons of times in production. What actually works: upload your files to Google Drive or Dropbox first, then drop the shareable links in your email instead of attaching directly. Bonus - smaller emails that deliver better. You could also switch to SendGrid or Amazon SES since they’re way more flexible with attachments, but you’ll need to set them up separately and might pay depending on how much you send.

Had this exact problem last year building an automated reporting system. It’s not your SMTP config - Gmail’s attachment filtering has gotten way stricter. Here’s what saved me: rename the MIME type instead of letting it auto-detect. Set ContentType to “application/octet-stream” when creating your Attachment object. Gmail treats it as a generic binary file instead of flagging it as dangerous. You can also try a custom Content-Disposition header. If that doesn’t work, go hybrid - detect the file type first and auto-upload blocked formats to cloud storage while sending allowed files normally.

gmail blocks certain file types. try zipping your files or changing the extensions like .docx to .doc_ then have the recipient rename it back. works most of the time!