私はデータベースからのデータのリストを持っています。私はデータベースにEmail IDを持っています。そのIDにメールを送信する必要があります。保存日が明日であれば、今日までに通知メールを送信する必要があります。アドレスからのAは、である必要があります:私のエラーは、「sendsystem.InvalidOperationExceptionすることができませんC#でsmtpを使用して電子メールを送信するには?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
namespace SendingEmail
{
public class SendingMail
{
public static void SendMail(string recipient, string subject, string
body, string attachmentFilename)
{
//method to send email
MailMessage mail = new MailMessage();
try
{
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com", 587);
SmtpServer.EnableSsl = true;
SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "my password");
string From = "my [email protected]";
string To = "email.com";
mail.Subject = "Test Mail - 1";
mail.Body = "mail with attachment";
MailMessage msg = new MailMessage(From, To);
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment
(@"C:\Users\rahul.chakrabarty\Desktop\logg.txt");
mail.Attachments.Add(attachment);
SmtpServer.Send(mail);
}
//To cathch Exception
catch (Exception ex)
{
Console.WriteLine("unable to send" + ex);
}
}
}
}
...電子メールを送信し、私は毎日それを送信するためにサービスを使用しますが、私の電子メールの一部が私のコードでworking..belowではありません」指定された。これは、あなたが言った
書式設定に影響するコメントを削除しました。彼らはちょうどノイズです –
AFAIK電子メールアドレスには空白を入れることはできません。 "文字列をFrom =" [email protected] ";; ' –
私は彼がメールアドレスを難読化していると仮定していました。 –