我想将文件附加到我的电子邮件中,但我没有选择特定文件,现在我必须预先设置要发送的文件,当然,现在我希望用户从中选择任何类型的文件他的手机或内存,它返回文件的路径,可以是照片,视频或文件
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("email2", "senha");
MailMessage mail = new MailMessage();
mail.Sender = new System.Net.Mail.MailAddress("email2");
mail.From = new MailAddress("email2");
mail.To.Add(new MailAddress("email1"));
mail.Subject = "Desembucha Aplicativo";
mail.Body = " Mensagem do Aplicativo<br/> Nome: " + nome.Text + "<br/> Email : " + email.Text + " <br/> Mensagem : " + mensagem.Text;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
Attachment anexado = new Attachment(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + @"/arquivo.txt", MediaTypeNames.Application.Octet);
mail.Attachments.Add(anexado);
try
{
client.Send(mail);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
AlertDialog alerta = builder.Create();
alerta.SetCancelable(true);
alerta.SetTitle("Mensagem enviada com sucesso");
alerta.SetMessage("Aguarde em breve daremos retorno de sua mensagem, Obrigado");
alerta.SetButton("OK", (s, ev) =>
{
Finish();
});
alerta.Show();
}
catch
{
Toast.MakeText(this, "Error", ToastLength.Short).Show();
}
finally
{
mail = null;
}