Expected parameter value, got "è.

  • Thread starter Thread starter Hani2693
  • Start date Start date
H

Hani2693

Guest
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("AKIAJDQ3YK2NF2CRURSQ",
"qMTlRqTTk2/7fTjmadu5dWrhWQbCQtQYyufUfRfA");

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,


Continue reading...
 
Back
Top