Hi
I have below code & i am getting error - "Cannot implicitly convert SapBobsCom.attachment to System.net.mail.attachment
SAPbobsCOM.Attachment attachment = new SAPbobsCOM.Attachment();
attachment.FileName = @"10.0.1.30\SAP_Attachments\250314_205951");
message.Attachments.Add(attachment);
Thanks
Azer EngazzouPosted Dec 9, 2025, 9:49 AM
Hello,
as Tas said, the error happens because SAPbobsCOM.Attachemnt and System.Net.Mail.Attachemnt are different types. You can't add a SAP attachment directly to a MailMessage. System.Net.Mail.Attachment requires a file path or stream, so you need to first get the attachment from SAP to your local system or a memory stream.
Tasadduq BurneyPosted Dec 9, 2025, 9:39 AM
Hey,
Hope you're keeping well.
SAPbobsCOM.AttachmentandSystem.Net.Mail.Attachmentare completely different types from unrelated namespaces, so you can’t pass one directly intoMailMessage.Attachments. You’ll need to retrieve the file path or binary stream from the SAP object (e.g., viaAttachment.Lines.SourcePathandAttachment.Lines.FileNamein the DI API), then create a newSystem.Net.Mail.Attachmentfrom aFileStreamorMemoryStreamand add that to the message. For example:using var stream = File.OpenRead(filePath); message.Attachments.Add(new System.Net.Mail.Attachment(stream, Path.GetFileName(filePath)));. Ensure the network path is accessible to the account running your code, especially if this is deployed to IIS or an Azure App Service.Thanks and regards,
Taz