asp.netでメールを送信するためにこのコードを使用しています:
System.Net.Mail の使用
public string SendEmail()
{
SmtpClient obj = new SmtpClient();
MailMessage Mailmsg = new MailMessage();
Mailmsg.To.Clear();
Recievers = new MailAddressCollection();
Recievers.Add(txtToAddress.Text);
SenderName = "Info";
SenderEmail = txtFromAddress.Text;
Subject = "subj";
Body = "body";
UseBcc = false;
if (UseBcc)
{
foreach (MailAddress RecieverItem in Recievers)
{
Mailmsg.Bcc.Add(RecieverItem);
}
}
else
{
foreach (MailAddress RecieverItem in Recievers)
{
Mailmsg.To.Add(RecieverItem);
}
}
Mailmsg.From = new MailAddress(SenderEmail, SenderName, System.Text.Encoding.UTF8);
Mailmsg.Subject = Subject;
Mailmsg.SubjectEncoding = Encoding.UTF8;
Mailmsg.BodyEncoding = System.Text.Encoding.UTF8;
Mailmsg.IsBodyHtml = false;
obj.Host = mail.domain.com;
System.Net.NetworkCredential BasicAuthenticationInfo = new System.Net.NetworkCredential("info@domain.com", "password");
obj.UseDefaultCredentials = false;
obj.Credentials = BasicAuthenticationInfo;
Mailmsg.Body = Body;
Mailmsg.IsBodyHtml = true;
try
{
obj.Send(Mailmsg);
return "sent";
}
catch (Exception ex)
{
return ex.ToString();
}
}
ドメインで定義されている受信者 ( mail@domain.comなど) に電子メールを正しく送信しますが、他のメール サーバー ( mail@yahoo.comなど) に電子メールを送信できません。
私のコードで何が間違っていますか?
(SmtpClient プロパティに関連している可能性がありますか? smtpclient.host をmail.mydomain.comに設定 し、ドメインで定義されているいずれかのメール アカウントのユーザー名とパスワードを使用しています)
ありがとう