.net - Adding an attachment to email using C# -
i'm using following code answer sending email in .net through gmail. trouble i'm having adding attachment email. how add attachment using code below?
using system.net.mail; var fromaddress = new mailaddress("from@gmail.com", "from name"); var toaddress = new mailaddress("to@example.com", "to name"); const string frompassword = "frompassword"; const string subject = "subject"; const string body = "body"; var smtp = new smtpclient { host = "smtp.gmail.com", port = 587, enablessl = true, deliverymethod = smtpdeliverymethod.network, usedefaultcredentials = false, credentials = new networkcredential(fromaddress.address, frompassword) }; using (var message = new mailmessage(fromaddress, toaddress) { subject = subject, body = body }) { smtp.send(message); }
thanks in advance.
the message
object created new mailmessage
method call has property .attachements
.
for example:
message.attachments.add(new attachment(pathtoattachment));
Comments
Post a Comment