c# - Sending hardcoded email with attachment -
i trying write code sending hard coded email attachment i-e don't want use buttons , text fields. want when program runs should automatically go location in drive , attach files , email email address have told program while coding.
the normal code buttons , text fields not work. see below normal code
mailmessage mail = new mailmessage(from.text, to.text, subject.text, body.text); mail.attachments.add(new attachment(attachment1.text)); smtpclient client = new smtpclient(smtp.text); client.port = 587; client.credentials = new system.net.networkcredential(username.text, password.text); client.enablessl = true; client.send(mail); messagebox.show("mail sent!", "success", messageboxbuttons.ok);
i have tried replacing from.text
, to.text
, subject.text
, body.text
, attachment1.text
string
string from="abc@gmail.com"; string attachment1=@"c:\image1.jpg";
they give me errors.
remove .text
after each variable, strings don't have text
property.
like this:
mailmessage mail = new mailmessage(from, to, subject, body);
Comments
Post a Comment