none
Expected parameter value, got "è.

    Pertanyaan

  • public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        //  private static Encoding _encoding = System.Text.Encoding.GetEncoding(850);
        protected void bt1_c(object sender, EventArgs e)
        {
            MailMessage mailMessage = new MailMessage();
            string from = "reciever@.com";
            string To = "sender@.com";
            string htmlBody = @"<html>
                                 <head></head>
                                   <body>
                                     <h1>Amazon SES Test (AWS SDK for .NET)</h1>
                                       <p>This email was sent with
                                          AWS SDK for .NET</a>.
                                       </p>
                                    </body>
                                 </html>";
    
            // Create the subject and body of the message.
    
            Amazon.SimpleEmail.Model.Content subject = new
            Amazon.SimpleEmail.Model.Content("HELLOOO");
            Amazon.SimpleEmail.Model.Content textBody = new
            Amazon.SimpleEmail.Model.Content(htmlBody);
            Body body = new Body(textBody);
    
            //Create a message with the specified subject and body.
            Message message = new Message(subject, body);
            mailMessage.From = new MailAddress(from);
    
            string attachment1 = Server.MapPath(Path.GetFileName("跃科人才思想领导力活动调研.pdf"));
            System.Net.Mail.Attachment objAttach = new
                    System.Net.Mail.Attachment(attachment1);
    
            Encoding chineseSimplified = Encoding.GetEncoding("GB2312");
            //Encoding windowsDefault = Encoding.GetEncoding("windows-1252");
            // objAttach.NameEncoding = System.Text.Encoding.GetEncoding(windowsDefault, true);
            objAttach.NameEncoding = chineseSimplified;
            mailMessage.Attachments.Add(objAttach);
    
            RawMessage rawMessage = new RawMessage();
            AWSCredentials credentials = new
            BasicAWSCredentials();
    
            using (var client = AWSClientFactory.CreateAmazonSimpleEmailServiceClient(credentials,
                  RegionEndpoint.USEast1))
            {
                using (MemoryStream memoryStream =
                   ConvertMailMessageToMemoryStream(mailMessage))
                {
                    rawMessage.Data = memoryStream;
                }
    
                SendRawEmailRequest request = new SendRawEmailRequest();
                request.RawMessage = rawMessage;
    
                request.Source = from;
                request.Destinations.Add(To);
                var response = client.SendRawEmail(request);
                lb2.Text = response.ToString();
                mailMessage.Dispose();
            }
        }
    
        public static MemoryStream ConvertMailMessageToMemoryStream(MailMessage message)
        {
            Assembly assembly = typeof(SmtpClient).Assembly;
            Type mailWriterType =
              assembly.GetType("System.Net.Mail.MailWriter");
    
            MemoryStream fileStream = new MemoryStream();
    
            ConstructorInfo mailWriterContructor =
             mailWriterType.GetConstructor(BindingFlags.Instance |
             BindingFlags.NonPublic, null, new[] { typeof(Stream) }, null);
            object mailWriter = mailWriterContructor.Invoke(new object[] {
                 fileStream });
            MethodInfo sendMethod = typeof(MailMessage).GetMethod("Send",
              BindingFlags.Instance | BindingFlags.NonPublic);
            sendMethod.Invoke(message, BindingFlags.Instance |
              BindingFlags.NonPublic, null, new[] { mailWriter, true, true },
              null);
    
            MethodInfo closeMethod = mailWriter.GetType().GetMethod("Close",
             BindingFlags.Instance | BindingFlags.NonPublic);
    
            closeMethod.Invoke(mailWriter, BindingFlags.Instance |
            BindingFlags.NonPublic, null, new object[] { }, null);
            return fileStream;
        }
    }

    I need to send an email via Amazon SES, but I am not able to. I've tried using all encoding formats but nothing seems to work for that attachment. It keeps throwing the same error When trying to Attach a Chinese File.

    Could someone help me in this.

    Thanks,


    • Dipindahkan oleh CoolDadTxMVP Selasa, 24 Juli 2018 15.23 Third party product
    • Diedit oleh Hani2693 Kamis, 02 Agustus 2018 06.56
    Selasa, 17 Juli 2018 05.31

Semua Balasan

  • Please craft a concise and complete example (console).

    What libraries are involved (Amazon)?

    Why do you load the MailWriter assembly manually?

    Selasa, 24 Juli 2018 08.05
  • Your question is related to a third party product. These forums are for questions specifically related to C# and Microsoft. Please post your questions related to Amazon's mail client in their forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Selasa, 24 Juli 2018 15.23
  • D'oh?

    You did not specify any size value in your code..

    Senin, 30 Juli 2018 10.19