0

ファイルを動的に添付してメールで送信したい。添付ファイル付きで送信する方法を誰か教えてください。

4

2 に答える 2

0

このコードで試すことができます

                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("...");/:Adjust your adress
                mail.From = new MailAddress("your_email_address@gmail.com");
                mail.To.Add("to_address");
                mail.Subject = "Test Mail";
                mail.Body = "mail with attachment";

                System.Net.Mail.Attachment attachment;
                attachment = new System.Net.Mail.Attachment("your attachment file");
                mail.Attachments.Add(attachment);

                SmtpServer.Port = ..; //Replace with your port number
                SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
于 2012-09-03T09:06:38.587 に答える
0

このコードを使用できます。

using System.Net.Mail;

private void SendEmail()
{
    MailMessage message = new MailMessage();
    message.From = new MailAddress("YourEmailAddress@domain.com");
    message.To.Add(new MailAddress("Recipient@domain.com"));
    message.Subject = "Subject";
    message.Body = "Email Message Body";

    // Add attachment
    string attachmentPath = Server.MapPath("~/AttachmentPath.jpg");
    message.Attachments.Add(new Attachment(attachmentPath));

    // Connect to GoDaddy SMTP
    SmtpClient smtp = new SmtpClient("relay-hosting.secureserver.net");
    smtp.Credentials = new System.Net.NetworkCredential("Username","Password");
    smtp.Port = 25;
    smtp.EnableSsl = false;

    // Send the message
    smtp.Send(message);
}
于 2012-09-03T09:07:19.290 に答える