Hi
Attachment does not contain a constructor that takes 1 arguments
C#
using (var message = new MailMessage(fromAddress.ToString(), address)
{
Subject = subject,
Body = body,
IsBodyHtml = true,
Priority = MailPriority.High
})
{
message.Attachments.Add(new SAPbobsCOM.Attachment(@"10.0.1.10\SAP_Attachments\file.txt"));
smtp.Send(message);
}Thanks

Emily FosterRank #3,495 · 415 reputationPosted Mar 15, 2025, 4:23 AM EDT
The error message "Attachment does not contain a constructor that takes 1 arguments" typically occurs in C# when there is an issue with how an object is being instantiated. In the provided code snippet, the error is likely related to the misuse of the constructor for adding an attachment to the message.
To address this error, you need to make sure that you are using the correct constructor when adding an attachment to the message. In the context of the code snippet you shared, it seems like you might be attempting to add an attachment of type `SAPbobsCOM.Attachment`, but the way you are adding it is incorrect.
Here's a possible correction to add the attachment correctly:
using (var message = new MailMessage(fromAddress.ToString(), address) { Subject = subject, Body = body, IsBodyHtml = true, Priority = MailPriority.High }) { Attachment attachment = new Attachment(@"10.0.1.10\SAP_Attachments\file.txt"); message.Attachments.Add(attachment); smtp.Send(message); }In the corrected code snippet, a new `Attachment` object is created with the file path specified, and then this attachment is added to the `message` before sending it via `smtp.Send(message)`.
By ensuring that you are using the correct constructor and following the proper syntax for adding attachments to an email message, you should be able to resolve this error. If you encounter any further issues or have additional questions, feel free to ask!