File link in a directory in the email

Asked

Viewed 44 times

-1

Good afternoon.

I am trying to fire an email through SSIS using the C# code whose email body has a "click here" to open a file that is in a directory. I already tried the HTML schema using "Click here and the VBA schema. I’ve even done it as the topic C# how to send an email containing a hyperlink using System.Net.Mail? could someone help me, please? the code is:

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;

    public void Main()
    {
        // TODO: Add your code here

        MailMessage msg = new MailMessage("[email protected]", "[email protected]", "Assunto", "Bom dia a todos."+"\r\n" + "\r\n" + "Arquivo atualizado. Para conferir,  <a href= \\xxxxx\\xxxxxxx\\xxxx\\bbbbb\\eeeeeeee\\arquivo.xlsx"><"Clique aqui"></a>");
     msg.IsBodyHtml = true;
        SmtpClient client = new SmtpClient("exchange.empresaX.com.br", 587);

        client.EnableSsl = true;

        client.DeliveryMethod = SmtpDeliveryMethod.Network;

        client.Credentials = new NetworkCredential("[email protected]","SENHA");

        client.Send(msg);


        Dts.TaskResult = (int)ScriptResults.Success;
    }

1 answer

2


You can use the protocol file to open a local archive in a path absolute:

string link = @"file:\\C:\caminho\para\o\arquivo.txt";

MailMessage msg = new MailMessage(
    "[email protected]",
    "[email protected]",
    "Assunto",
    "Bom dia a todos." + "\r\n" + "\r\n" + $"Arquivo atualizado. Para conferir, <a href=\"{link}\">Clique aqui</a>");
msg.IsBodyHtml = true;

It does not support relative addresses, such as .\arquivo.txt, for example. You must specify the full file path, the file name and its extension.

Remembering that, the file must exist on the destination machine.

If the file is online, use https. If on an FTP server, ftp.

Read more about the protocol file.

  • Good afternoon Cypherpotato, The code compiled, however in the body of the email, is only appearing "Updated file. To check," and does not appear the Click here =(

  • @fercs89 is because the clique aqui was as <"clique aqui"> and that’s html syntax error. I fixed the answer.

  • 1

    It worked!!! Thank you so much @Cypherpotato !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.