質問編集履歴
4
質問内容の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,228 +18,8 @@
|
|
18
18
|
|
19
19
|
Gmailに送れない問題が発生しております。
|
20
20
|
|
21
|
-
* Gmail側で電子署名付きメール自体が受信できていない状態です。
|
22
|
-
|
23
|
-
* 電子署名を付与しなければ問題なく送れます。
|
24
|
-
|
25
|
-
* 実行時にプログラムソース上ではエラーとならず、送信サーバに以下エラー内容の通知が届きます。
|
26
|
-
|
27
|
-
* エラー内容のFromやドメインの設定について問題ないことは確認済みです。
|
28
|
-
|
29
|
-
* 想定ではS/MIME関連のエラーかと考えているのですが、
|
30
|
-
|
31
|
-
こちらの内容のエラーが出力されておらず原因の当たりが付けられない状況です。
|
32
|
-
|
33
21
|
|
34
22
|
|
35
23
|
制約として、Gmailの設定は修正せずにプログラムソースのみで対応したいです。
|
36
24
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
### エラー内容(送信サーバに送られた内容)
|
42
|
-
|
43
|
-
Hi. This is the qmail-send program at XXX.XXX.jp.
|
44
|
-
|
45
|
-
I'm afraid I wasn't able to deliver your message to the following addresses.
|
46
|
-
|
47
|
-
This is a permanent error; I've given up. Sorry it didn't work out.
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
<XXX@XXX.com>:
|
52
|
-
|
53
|
-
00.000.000.00 failed after I sent the message.
|
54
|
-
|
55
|
-
Remote host said: XXX-X.X.X [XXX.XXX.XXX.XXX 11] Our system has detected that this message is
|
56
|
-
|
57
|
-
550-5.7.1 not RFC 5322 compliant:
|
58
|
-
|
59
|
-
550-5.7.1 'From' header is missing.
|
60
|
-
|
61
|
-
550-5.7.1 To reduce the amount of spam sent to Gmail, this message has been
|
62
|
-
|
63
|
-
550-5.7.1 blocked. Please visit
|
64
|
-
|
65
|
-
550-5.7.1 https://support.google.com/mail/?p=RfcMessageNonCompliant
|
66
|
-
|
67
|
-
550 5.7.1 and review RFC 5322 specifications for more information. XXXXXXXXXXXXXXX.XXX - gsmtp
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
--- Below this line is a copy of the message.
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
Return-Path: <XXXX@XXXX>
|
76
|
-
|
77
|
-
X-ACCEPT-IP: XXX.XXX.XXX.XXX
|
78
|
-
|
79
|
-
Received: (qmail XXXXX invoked by SAV XXXXXXXX.XXX by uid 0); XX XXX XXXX XX:XX:XX +0900
|
80
|
-
|
81
|
-
Received: from unknown (HELO XXX) (XXX@XXX)
|
82
|
-
|
83
|
-
by XXXX.XXXX.XX (XXX.XXX.XXX.XXX) with ESMTPA; XX XXX XXXX XX:XX:XX +0900
|
84
|
-
|
85
|
-
MIME-Version: 1.0
|
86
|
-
|
87
|
-
From: "sample" <XXX@XXX>
|
88
|
-
|
89
|
-
To: "XXXX@XXXX.com " <XXXX@XXXX.com >
|
90
|
-
|
91
|
-
Date: XX Apr XXXX XX:XX:XX +0900
|
92
|
-
|
93
|
-
Subject: XXXXXX
|
94
|
-
|
95
|
-
Content-Type: application/pkcs7-mime; name=smime.p7m; smime-type=signed-data
|
96
|
-
|
97
|
-
Content-Transfer-Encoding: base64
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
### ソースコード
|
102
|
-
|
103
|
-
```C#
|
104
|
-
|
105
|
-
using System;
|
106
|
-
|
107
|
-
using System.Net.Mail;
|
108
|
-
|
109
|
-
using System.Windows.Forms;
|
110
|
-
|
111
|
-
using System.Text;
|
112
|
-
|
113
|
-
using System.Security.Cryptography.Pkcs;
|
114
|
-
|
115
|
-
using System.IO;
|
116
|
-
|
117
|
-
using System.Security.Cryptography.X509Certificates;
|
118
|
-
|
119
|
-
using System.Security.Cryptography;
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
namespace MailSignatureTest
|
124
|
-
|
125
|
-
{
|
126
|
-
|
127
|
-
public partial class MailSignatureTest : Form
|
128
|
-
|
129
|
-
{
|
130
|
-
|
131
|
-
public MailSignatureTest()
|
132
|
-
|
133
|
-
{
|
134
|
-
|
135
|
-
InitializeComponent();
|
136
|
-
|
137
|
-
}
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
private void button2_Click(object sender, EventArgs e)
|
142
|
-
|
143
|
-
{
|
144
|
-
|
145
|
-
var charCode = "UTF-8";
|
146
|
-
|
147
|
-
var mailBody = "メールテスト(本文)";
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
try
|
152
|
-
|
153
|
-
{
|
154
|
-
|
155
|
-
MailMessage message = new MailMessage();
|
156
|
-
|
157
|
-
message.From = new MailAddress("test01@hoge.co.jp", "test01@hoge.co.jp");
|
158
|
-
|
159
|
-
message.To.Add(new MailAddress("test02@gmail.com", "test02@gmail.com"));
|
160
|
-
|
161
|
-
message.Subject = "メールテストです。";
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
StringBuilder buffer = new StringBuilder();
|
166
|
-
|
167
|
-
buffer.Append("MIME-Version: 1.0\r\n");
|
168
|
-
|
169
|
-
buffer.Append("Content-Type: text/plain; charset=" + charCode + "\r\n");
|
170
|
-
|
171
|
-
buffer.Append("Content-Transfer-Encoding: base64\r\n\r\n");
|
172
|
-
|
173
|
-
Encoding encd = Encoding.GetEncoding(charCode);
|
174
|
-
|
175
|
-
buffer.Append(Convert.ToBase64String(encd.GetBytes(mailBody)));
|
176
|
-
|
177
|
-
var MimePart = buffer.ToString();
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
byte[] Data = Encoding.UTF8.GetBytes(MimePart);
|
182
|
-
|
183
|
-
ContentInfo Content = new ContentInfo(Data);
|
184
|
-
|
185
|
-
SignedCms SignedCms = new SignedCms(Content, false);
|
186
|
-
|
187
|
-
var forwardCertificate = Path.Combine(@"C:\Test\Certificate\", "test01.pfx");
|
188
|
-
|
189
|
-
var forwardCertificatePW = "testpass01";
|
190
|
-
|
191
|
-
X509Certificate2 Certificate = new X509Certificate2(forwardCertificate, forwardCertificatePW);
|
192
|
-
|
193
|
-
System.Security.Cryptography.Pkcs.CmsSigner Signer = new System.Security.Cryptography.Pkcs.CmsSigner(System.Security.Cryptography.Pkcs.SubjectIdentifierType.IssuerAndSerialNumber, Certificate);
|
194
|
-
|
195
|
-
Signer.DigestAlgorithm = new Oid("SHA256");
|
196
|
-
|
197
|
-
Signer.SignedAttributes.Add(new Pkcs9SigningTime(DateTime.Now));
|
198
|
-
|
199
|
-
SignedCms.ComputeSignature(Signer);
|
200
|
-
|
201
|
-
byte[] SignedBytes = SignedCms.Encode();
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
MemoryStream Stream = new MemoryStream(SignedBytes);
|
206
|
-
|
207
|
-
AlternateView View = new AlternateView(Stream, "application/pkcs7-mime; smime-type=signed-data;name=smime.p7m");
|
208
|
-
|
209
|
-
message.AlternateViews.Add(View);
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
using (var sc = new SmtpClient())
|
214
|
-
|
215
|
-
{
|
216
|
-
|
217
|
-
sc.Host = "XXX.XXX.XXX.XXX";
|
218
|
-
|
219
|
-
sc.Port = int.Parse("XXX");
|
220
|
-
|
221
|
-
sc.Credentials = new System.Net.NetworkCredential("testid", "testpass");
|
222
|
-
|
223
|
-
sc.Send(message);
|
224
|
-
|
225
|
-
}
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
}
|
230
|
-
|
231
|
-
catch (Exception)
|
232
|
-
|
233
|
-
{
|
234
|
-
|
235
|
-
throw;
|
236
|
-
|
237
|
-
}
|
238
|
-
|
239
|
-
}
|
240
|
-
|
241
|
-
}
|
242
|
-
|
243
|
-
}
|
244
|
-
|
245
|
-
```
|
25
|
+
他の送信方法がありましたらご教授いただけますと幸いです。
|
3
「発生している問題」の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,6 +24,12 @@
|
|
24
24
|
|
25
25
|
* 実行時にプログラムソース上ではエラーとならず、送信サーバに以下エラー内容の通知が届きます。
|
26
26
|
|
27
|
+
* エラー内容のFromやドメインの設定について問題ないことは確認済みです。
|
28
|
+
|
29
|
+
* 想定ではS/MIME関連のエラーかと考えているのですが、
|
30
|
+
|
31
|
+
こちらの内容のエラーが出力されておらず原因の当たりが付けられない状況です。
|
32
|
+
|
27
33
|
|
28
34
|
|
29
35
|
制約として、Gmailの設定は修正せずにプログラムソースのみで対応したいです。
|
2
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,9 +20,9 @@
|
|
20
20
|
|
21
21
|
* Gmail側で電子署名付きメール自体が受信できていない状態です。
|
22
22
|
|
23
|
-
* 電子署名を付与しければ問題なく送れます。
|
23
|
+
* 電子署名を付与しなければ問題なく送れます。
|
24
|
-
|
24
|
+
|
25
|
-
* 実行時にプログラムソース上ではエラーとならず、送信サーバに以下
|
25
|
+
* 実行時にプログラムソース上ではエラーとならず、送信サーバに以下エラー内容の通知が届きます。
|
26
26
|
|
27
27
|
|
28
28
|
|
1
エラー内容、ソースコードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
### 発生している問題
|
13
|
+
### 発生している問題
|
14
14
|
|
15
15
|
|
16
16
|
|
@@ -22,8 +22,218 @@
|
|
22
22
|
|
23
23
|
* 電子署名を付与しければ問題なく送れます。
|
24
24
|
|
25
|
+
* 実行時にプログラムソース上ではエラーとならず、送信サーバに以下、エラー内容の通知が届きます。
|
26
|
+
|
25
27
|
|
26
28
|
|
27
29
|
制約として、Gmailの設定は修正せずにプログラムソースのみで対応したいです。
|
28
30
|
|
29
31
|
修正ポイントや、他の送信方法がありましたらご教授いただけますと幸いです。
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
### エラー内容(送信サーバに送られた内容)
|
36
|
+
|
37
|
+
Hi. This is the qmail-send program at XXX.XXX.jp.
|
38
|
+
|
39
|
+
I'm afraid I wasn't able to deliver your message to the following addresses.
|
40
|
+
|
41
|
+
This is a permanent error; I've given up. Sorry it didn't work out.
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
<XXX@XXX.com>:
|
46
|
+
|
47
|
+
00.000.000.00 failed after I sent the message.
|
48
|
+
|
49
|
+
Remote host said: XXX-X.X.X [XXX.XXX.XXX.XXX 11] Our system has detected that this message is
|
50
|
+
|
51
|
+
550-5.7.1 not RFC 5322 compliant:
|
52
|
+
|
53
|
+
550-5.7.1 'From' header is missing.
|
54
|
+
|
55
|
+
550-5.7.1 To reduce the amount of spam sent to Gmail, this message has been
|
56
|
+
|
57
|
+
550-5.7.1 blocked. Please visit
|
58
|
+
|
59
|
+
550-5.7.1 https://support.google.com/mail/?p=RfcMessageNonCompliant
|
60
|
+
|
61
|
+
550 5.7.1 and review RFC 5322 specifications for more information. XXXXXXXXXXXXXXX.XXX - gsmtp
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
--- Below this line is a copy of the message.
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
Return-Path: <XXXX@XXXX>
|
70
|
+
|
71
|
+
X-ACCEPT-IP: XXX.XXX.XXX.XXX
|
72
|
+
|
73
|
+
Received: (qmail XXXXX invoked by SAV XXXXXXXX.XXX by uid 0); XX XXX XXXX XX:XX:XX +0900
|
74
|
+
|
75
|
+
Received: from unknown (HELO XXX) (XXX@XXX)
|
76
|
+
|
77
|
+
by XXXX.XXXX.XX (XXX.XXX.XXX.XXX) with ESMTPA; XX XXX XXXX XX:XX:XX +0900
|
78
|
+
|
79
|
+
MIME-Version: 1.0
|
80
|
+
|
81
|
+
From: "sample" <XXX@XXX>
|
82
|
+
|
83
|
+
To: "XXXX@XXXX.com " <XXXX@XXXX.com >
|
84
|
+
|
85
|
+
Date: XX Apr XXXX XX:XX:XX +0900
|
86
|
+
|
87
|
+
Subject: XXXXXX
|
88
|
+
|
89
|
+
Content-Type: application/pkcs7-mime; name=smime.p7m; smime-type=signed-data
|
90
|
+
|
91
|
+
Content-Transfer-Encoding: base64
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
### ソースコード
|
96
|
+
|
97
|
+
```C#
|
98
|
+
|
99
|
+
using System;
|
100
|
+
|
101
|
+
using System.Net.Mail;
|
102
|
+
|
103
|
+
using System.Windows.Forms;
|
104
|
+
|
105
|
+
using System.Text;
|
106
|
+
|
107
|
+
using System.Security.Cryptography.Pkcs;
|
108
|
+
|
109
|
+
using System.IO;
|
110
|
+
|
111
|
+
using System.Security.Cryptography.X509Certificates;
|
112
|
+
|
113
|
+
using System.Security.Cryptography;
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
namespace MailSignatureTest
|
118
|
+
|
119
|
+
{
|
120
|
+
|
121
|
+
public partial class MailSignatureTest : Form
|
122
|
+
|
123
|
+
{
|
124
|
+
|
125
|
+
public MailSignatureTest()
|
126
|
+
|
127
|
+
{
|
128
|
+
|
129
|
+
InitializeComponent();
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
private void button2_Click(object sender, EventArgs e)
|
136
|
+
|
137
|
+
{
|
138
|
+
|
139
|
+
var charCode = "UTF-8";
|
140
|
+
|
141
|
+
var mailBody = "メールテスト(本文)";
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
try
|
146
|
+
|
147
|
+
{
|
148
|
+
|
149
|
+
MailMessage message = new MailMessage();
|
150
|
+
|
151
|
+
message.From = new MailAddress("test01@hoge.co.jp", "test01@hoge.co.jp");
|
152
|
+
|
153
|
+
message.To.Add(new MailAddress("test02@gmail.com", "test02@gmail.com"));
|
154
|
+
|
155
|
+
message.Subject = "メールテストです。";
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
StringBuilder buffer = new StringBuilder();
|
160
|
+
|
161
|
+
buffer.Append("MIME-Version: 1.0\r\n");
|
162
|
+
|
163
|
+
buffer.Append("Content-Type: text/plain; charset=" + charCode + "\r\n");
|
164
|
+
|
165
|
+
buffer.Append("Content-Transfer-Encoding: base64\r\n\r\n");
|
166
|
+
|
167
|
+
Encoding encd = Encoding.GetEncoding(charCode);
|
168
|
+
|
169
|
+
buffer.Append(Convert.ToBase64String(encd.GetBytes(mailBody)));
|
170
|
+
|
171
|
+
var MimePart = buffer.ToString();
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
byte[] Data = Encoding.UTF8.GetBytes(MimePart);
|
176
|
+
|
177
|
+
ContentInfo Content = new ContentInfo(Data);
|
178
|
+
|
179
|
+
SignedCms SignedCms = new SignedCms(Content, false);
|
180
|
+
|
181
|
+
var forwardCertificate = Path.Combine(@"C:\Test\Certificate\", "test01.pfx");
|
182
|
+
|
183
|
+
var forwardCertificatePW = "testpass01";
|
184
|
+
|
185
|
+
X509Certificate2 Certificate = new X509Certificate2(forwardCertificate, forwardCertificatePW);
|
186
|
+
|
187
|
+
System.Security.Cryptography.Pkcs.CmsSigner Signer = new System.Security.Cryptography.Pkcs.CmsSigner(System.Security.Cryptography.Pkcs.SubjectIdentifierType.IssuerAndSerialNumber, Certificate);
|
188
|
+
|
189
|
+
Signer.DigestAlgorithm = new Oid("SHA256");
|
190
|
+
|
191
|
+
Signer.SignedAttributes.Add(new Pkcs9SigningTime(DateTime.Now));
|
192
|
+
|
193
|
+
SignedCms.ComputeSignature(Signer);
|
194
|
+
|
195
|
+
byte[] SignedBytes = SignedCms.Encode();
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
MemoryStream Stream = new MemoryStream(SignedBytes);
|
200
|
+
|
201
|
+
AlternateView View = new AlternateView(Stream, "application/pkcs7-mime; smime-type=signed-data;name=smime.p7m");
|
202
|
+
|
203
|
+
message.AlternateViews.Add(View);
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
using (var sc = new SmtpClient())
|
208
|
+
|
209
|
+
{
|
210
|
+
|
211
|
+
sc.Host = "XXX.XXX.XXX.XXX";
|
212
|
+
|
213
|
+
sc.Port = int.Parse("XXX");
|
214
|
+
|
215
|
+
sc.Credentials = new System.Net.NetworkCredential("testid", "testpass");
|
216
|
+
|
217
|
+
sc.Send(message);
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
catch (Exception)
|
226
|
+
|
227
|
+
{
|
228
|
+
|
229
|
+
throw;
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
```
|