パスより多くの価値:私は、これはあなたが探しているものだと思います
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Mail;
namespace ConsoleApplication3
{
public class GmailAccount
{
public string Username;
public string Password;
public string DisplayName;
public string Address
{
get
{
return Username + "@gmail.com";
}
}
private SmtpClient client;
public GmailAccount(string username, string password, string displayName = null)
{
Username = username;
Password = password;
DisplayName = displayName;
client = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(Address, password)
};
}
public void SendMessage(string targetAddress, string subject, string body, params string[] files)
{
MailMessage message = new MailMessage(new MailAddress(Address, DisplayName), new MailAddress(targetAddress))
{
Subject = subject,
Body = body
};
foreach (string file in files)
{
Attachment attachment = new Attachment(file);
message.Attachments.Add(attachment);
}
client.Send(message);
}
}
class Program
{
static void Main(string[] args)
{
GmailAccount acc = new GmailAccount("username", "password", "Caption");
acc.SendMessage("[email protected]", "Hello World!", "like in the title...", "C:\\temp.rar");
}
}
}
こんにちはたくは数10230920スパムボットこと:youreのだけ郵送し、それにサインアップすることにしたい人を郵送しない限り、Pを、その頼まれて多くの助けを期待してはいけませんここ数回:P – RhysW
多くのこと...私は自分のコードと同様のコードで作業しますが、1つ以上の添付ファイルを送信することに問題があります。 – John
ジョンのポイントは、あなたがすでに試したことを見せてくれました。それがうまくいかない理由を言うことができます... – RhysW