Tengo el siguiente problema, estoy utilizando la API de Amazon para el envío de correos, este es SES, ya el correo me envía bien, pero al momento de adjuntar un pdf me genera problema, ya que cuando llega el correo, intento abrir el pdf y dice que este está dañado. Estoy utilizando vb.net
Este es mi codigo
Dim archivo = Path.Combine(Server.MapPath("~\ruta"), "prueba.pdf")
Dim stream = New MemoryStream(Encoding.UTF8.GetBytes("To: kgjdj@gmail" &
vbLf & "From: prueba@gmail" &
vbLf & "Subject: Prueba" &
vbLf & "Content-Type: multipart/alternative;" &
vbLf & " boundary=YWVhZDFlY2QzMGQ2N2U0YTZmODU" &
vbLf & "Content-Transfer-Encoding: 8bit" &
vbLf & "" &
vbLf & "--YWVhZDFlY2QzMGQ2N2U0YTZmODU" &
vbLf & "Content-Type: text/plain; charset=us-ascii" &
vbLf & "" &
vbLf & "" &
vbLf & "--YWVhZDFlY2QzMGQ2N2U0YTZmODU" &
vbLf & "Content-Type: text/html; charset=us-ascii" &
vbLf & "" &
vbLf & cuerpo &
vbLf & "" &
vbLf & "" &
vbLf & "" &
vbLf & "--YWVhZDFlY2QzMGQ2N2U0YTZmODU" &
vbLf & "Content-Type: application/pdf;" &
vbLf & "Content-Disposition: attachment; filename=Prueba.pdf" &
vbLf & "Content-Transfer-Encoding: base64" &
vbLf & "" &
vbLf & archivo &
vbLf & "" &
vbLf & "--YWVhZDFlY2QzMGQ2N2U0YTZmODU--"))
Dim senderAddress = "prueba@gmail"
Dim receiverAddress = "kgjdj@gmail"
Dim lista = New List(Of String) From {
receiverAddress
}
Using client = New AmazonSimpleEmailServiceClient(RegionEndpoint.USEast1)
Dim sendRequest = New SendRawEmailRequest With {
.Source = senderAddress,
.Destinations = lista,
.RawMessage = New RawMessage With {
.Data = Stream
}
}
Try
Console.WriteLine("Sending email using Amazon SES...")
Dim response = client.SendRawEmail(sendRequest)
Console.WriteLine("The email was sent successfully.")
Catch ex As Exception
Console.WriteLine("The email was not sent.")
Console.WriteLine("Error message: " & ex.Message)
End Try
End Using
stream
es lo que está matando alPDF
. No conozco el cliente SES de Amazon, pero he trabajado bastante con correos en VB.NET y por experiencia y por lo que veo en tu código te sugiero que busques la documentación de SES. – Mauricio Contreras el 15 ene. 19 a las 16:35