amazon WS SMTPを使用して電子メールを送信しようとしていますが、成功して送信していますが、電子メールは受信しません。私は添付ファイルなしでそれを送るとき、私はそれを成功と受け取る。Amazon AWS SMTPを使用して添付ファイル付き電子メールを送信
1
A
答えて
1
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-net.htmlは、私はあなたの問題は、おそらくあなたのメッセージに正しく添付ファイルを追加していないことだと思う:
は、ここに私のコード
// Create an SMTP client with the specified host name and port.
using (SmtpClient client = new SmtpClient(ssHost, ssPort))
{
// Create a network credential with your SMTP user name and password.
client.Credentials = new System.Net.NetworkCredential(ssSMTP_Username, ssSMTP_Password);
// Use SSL when accessing Amazon SES. The SMTP session will begin on an unencrypted connection, and then
// the client will issue a STARTTLS command to upgrade to an encrypted connection using SSL.
client.EnableSsl = true;
// Send the email.
MailMessage message = new MailMessage();
try
{
//creates a messages with the all data
message.From = new MailAddress(ssFrom, ssFromName);
//message.To.Add(ssTo);
//To
List<String> toAddresses = ssTo.Split(',').ToList();
foreach (String toAddress in toAddresses)
{
message.To.Add(new MailAddress(toAddress));
}
//cc
List<String> ccAddresses = ssCC.Split(',').Where(y => y != "").ToList();
foreach (String ccAddress in ccAddresses)
{
message.CC.Add(new MailAddress(ccAddress));
}
//bcc
List<String> BccAddresses = ssBcc.Split(',').Where(y => y != "").ToList();
foreach (String ccAddress in ccAddresses)
{
message.Bcc.Add(new MailAddress(ccAddress));
}
//replyTo
if (ssReplyTo != null)
{
message.ReplyToList.Add(new MailAddress(ssReplyTo));
}
//email
message.Subject = ssSubject;
message.Body = ssBody;
message.IsBodyHtml = true;
//Attachment
foreach (RCAttachmentRecord attchmentRec in ssAttachmenstList){
System.IO.MemoryStream ms = new System.IO.MemoryStream(attchmentRec.ssSTAttachment.ssBinary);
Attachment attach = new Attachment(ms, attchmentRec.ssSTAttachment.ssFilename);
message.Attachments.Add(attach);
ssErrorMessage = ssErrorMessage + "||" + attchmentRec.ssSTAttachment.ssFilename+"lenght:"+attchmentRec.ssSTAttachment.ssBinary.Length;
}
client.Send(message);
}
ソースです。
添付ファイル付きの1つのメッセージを送信できました。 your source link aboveから直接取得したコードから始めました。私はanother SO article about the missing content type problemからコードを追加しました。
添付ファイルは、マイドキュメントフォルダのWord文書Lebowski.docx
です。同様のシンプルなWord文書を作成し、次のコードを実行して単一の電子メールで簡単な添付ファイルを送信できることを確認することをお勧めします。
は、次のコードは私のために首尾よく働いた:
namespace SESTest
{
using System;
using System.Net.Mail;
namespace AmazonSESSample
{
class Program
{
static void Main(string[] args)
{
const String FROM = "from-email"; // Replace with your "From" address. This address must be verified.
const String TO = "to-email"; // Replace with a "To" address. If your account is still in the
// sandbox, this address must be verified.
const String SUBJECT = "Amazon SES test (SMTP interface accessed using C#)";
const String BODY = "This email and attachment was sent through the Amazon SES SMTP interface by using C#.";
// Supply your SMTP credentials below. Note that your SMTP credentials are different from your AWS credentials.
const String SMTP_USERNAME = "user-creds"; // Replace with your SMTP username.
const String SMTP_PASSWORD = "password"; // Replace with your SMTP password.
// Amazon SES SMTP host name.
const String HOST = "your-region.amazonaws.com";
// The port you will connect to on the Amazon SES SMTP endpoint. We are choosing port 587 because we will use
// STARTTLS to encrypt the connection.
const int PORT = 2587;
// Create an SMTP client with the specified host name and port.
using (System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(HOST, PORT))
{
// Create a network credential with your SMTP user name and password.
client.Credentials = new System.Net.NetworkCredential(SMTP_USERNAME, SMTP_PASSWORD);
// Use SSL when accessing Amazon SES. The SMTP session will begin on an unencrypted connection, and then
// the client will issue a STARTTLS command to upgrade to an encrypted connection using SSL.
client.EnableSsl = true;
// Send the email.
try
{
Console.WriteLine("Attempting to send an email through the Amazon SES SMTP interface...");
var mailMessage = new MailMessage()
{
Body = BODY,
Subject = SUBJECT,
From = new MailAddress(FROM)
};
mailMessage.To.Add(new MailAddress(TO));
//REMOVE THIS CODE
//System.IO.MemoryStream ms = new System.IO.MemoryStream(attchmentRec.ssSTAttachment.ssBinary);
//Attachment attach = new Attachment(ms, attchmentRec.ssSTAttachment.ssFilename);
//mailMessage.Attachments.Add(attach);
System.Net.Mime.ContentType contentType = new System.Net.Mime.ContentType();
contentType.MediaType = System.Net.Mime.MediaTypeNames.Application.Octet;
contentType.Name = "Lebowski.docx";
mailMessage.Attachments.Add(new Attachment("C:\\users\\luis\\Documents\\Lebowski.docx", contentType));
client.Send(mailMessage);
Console.WriteLine("Email sent!");
}
catch (Exception ex)
{
Console.WriteLine("The email was not sent.");
Console.WriteLine("Error message: " + ex.Message);
}
}
Console.Write("Press any key to continue...");
Console.ReadKey();
}
}
}
}
あなたは、あなたがにあなたのssAttachmentsList
からバイナリを取得する方法で作業を開始することができ、あなたの口座から1つの添付ファイル付きの電子メールを送信できることを証明したらあなたの電子メールと、それぞれに割り当てられた正しいコンテンツタイプ。しかし、あなたは私がこの時点でそれを判断するのに十分なコードやコンテキストを提供していませんでした。私はこのコードがあなたの添付ファイルの問題を解決するのを助けることを望んでいます。
関連する問題
- 1. 電子メールの添付ファイルを送信
- 2. ZF2に添付ファイルを添付した電子メールを送信
- 3. S/MIME(PHP)を使用して添付ファイル付きの電子メールを送信
- 4. Driod X送信添付ファイル電子メール
- 5. 添付ファイル付きの複数の電子メールに電子メールを送信
- 6. ruby net/smtpを使用して添付ファイル付きのメールを送信
- 7. 添付ファイル付きのAWS SESで電子メールを送信する - Ruby
- 8. Amazon SESを使用してC#で添付ファイル付きの電子メールを送信
- 9. MS Access VBA添付ファイル付き電子メールを送信
- 10. Mac端末が添付ファイル付きで電子メールを送信
- 11. 添付ファイル付きの電子メールを送信
- 12. Djangoで添付ファイル付きの電子メールを送信する
- 13. 添付ファイル付き電子メールをJavaで送信する
- 14. asp.net mvcを使用してGodaddyの電子メールワークスペースで添付ファイルを添付した電子メールを送信
- 15. 添付ファイルとしてログファイルを添付した電子メールを送信
- 16. vb.netでデフォルトの電子メールクライアントを使用して添付ファイル付きの電子メールを送信する方法
- 17. python + smtp添付ファイル付きのメールを送信するには?
- 18. 電子メールの添付ファイルとしてpdfを送信
- 19. Amazon AWSとPHPを使用して添付ファイル付きメールを送信する際にエラーが発生する
- 20. Gmailで添付ファイルRを添付した電子メールを送信
- 21. ループバック電子メールデータソースを添付した電子メールを送信
- 22. OpenXMLを使用してメモリに電子メールの添付ファイルを送信する
- 23. djangoでオプションの添付ファイルを使用して電子メールを送信
- 24. Microsoft.Graph添付ファイル付きメールを送信
- 25. 添付ファイル付きメールを送信
- 26. Shellとsmtpを使用して添付ファイルとともに電子メール本文にコンテンツを送信する
- 27. 流星 - 入力ファイルから添付ファイル付きの電子メールを送信
- 28. PHPは添付ファイル付きで電子メールを送信しません
- 29. 添付ファイル付きの電子メールをPHPで送信しますか?
- 30. VBA:IBMノートで電子メール(添付ファイル付き)を送信しますか?
もっとコードを投稿できますか?あなたを助けるために、あなたは 'ssAttachmenstList'をどのように定義し、どのように設定するのかを知る必要があります。 – Taterhead
この質問をチェックして、あなたを助けることができるかもしれませんか? http://stackoverflow.com/questions/2825950/sending-email-with-attachments-from-c-attachments-arrive-as-part-1-2-in-thunde –
ArrayListの変数@taterheadイメージ – Luis