Fügen Sie eine Methode bei C# mit ASSOSPLE.EMAIL hinzu, aber ich erhalte diesen Fehler 'Mapiattachment' nichtC#

Ein Treffpunkt für C#-Programmierer
Guest
 Fügen Sie eine Methode bei C# mit ASSOSPLE.EMAIL hinzu, aber ich erhalte diesen Fehler 'Mapiattachment' nicht

Post by Guest »

im folgenden Code, irgendwie die neue Mapiattachment in diesem Abschnitt

Code: Select all

//Create a new MapiAttachment using the byte array
< /code>
ist der folgende Fehler: < /p>

CS1729 'Mapiattachment' enthält keinen Konstruktor, der 2
Arguments.
< /blockquote>
Irgendwelche Zeiger, wie man dies umgeht? < /p>
private void AttachFileToEmail(MapiMessage email, string filePath)
{
if (!File.Exists(filePath))
{
MessageBox.Show($"File not found: {filePath}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

try
{
// Read the file as a byte array
byte[] fileBytes = File.ReadAllBytes(filePath);

// Get the file name
string fileName = Path.GetFileName(filePath);

// Create a new MapiAttachment using the byte array
MapiAttachment attachment = new MapiAttachment(fileName, new MemoryStream(fileBytes));

// Add the attachment to the email
email.Attachments.Add(attachment);
}
catch (Exception ex)
{
MessageBox.Show($"Error attaching file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}`
< /code>
Ich habe auch den folgenden Code ausprobiert, aber immer noch keine Würfel, da ich einen weiteren Fehler erhielt < /p>

CS1503: Argument 2: Kann nicht [url=viewtopic.php?t=12659]Konvertieren[/url] Sie von 'system.io.memoryStream' in
'asspin.private void AttachFileToEmail(MapiMessage email, string filePath)
{
if (!File.Exists(filePath))
{
MessageBox.Show($"File not found: {filePath}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

try
{
string fileName = Path.GetFileName(filePath);

// Read file bytes
byte[] fileBytes = File.ReadAllBytes(filePath);

// Create a memory stream from the file bytes
using (MemoryStream memoryStream = new MemoryStream(fileBytes))
{
// Add the attachment using the correct method
email.Attachments.Add(fileName, memoryStream);
}
}
catch (Exception ex)
{
MessageBox.Show($"Error attaching file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post