How to generate a fax and send it in code

RSolberg picture RSolberg · Jun 12, 2009 · Viewed 10.9k times · Source

I have a business requirement to generate a fax and send it to the recipient. I know the recipients name and fax number and there is a PDF that will be attached. This process will run daily and consist of 100 records to process each time. I was under the impression that this could be done by sending an email to the fax machine and a quick test in Outlook worked just fine. However, if I were to try and do the same thing in code, I get an error about the mail address being invalid.

MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("[Fax:myUser@5555555555]"));

What are my options for sending faxes from code? (.NET) These faxes are confidential in nature...


EDITED INFO

My company does use Right Fax.

Answer

Jon Erickson picture Jon Erickson · Jun 18, 2009

Here is some code that may help. This is using the Right Fax COM API Library (rfcomapi.dll)

RFCOMAPILib.FaxServerClass faxserver = new RFCOMAPILib.FaxServerClass();
faxserver.ServerName = "ServerName";
faxserver.Protocol = RFCOMAPILib.CommunicationProtocolType.cpNamedPipes;
faxserver.UseNTAuthentication = RFCOMAPILib.BoolType.True;
faxserver.OpenServer();

RFCOMAPILib.Fax fax = (RFCOMAPILib.Fax) faxserver.get_CreateObject(RFCOMAPILib.CreateObjectType.coFax);

// set up your 'fax' object the way you want it, below is just some sample options
fax.ToName = "John Doe";
fax.ToFaxNumber = "4255551111";
fax.ToVoiceNumber = "4255550000";
fax.ToCompany = "ACME";
fax.FromName = "My Company";
fax.FromVoiceNumber = "4255552222";

fax.Send();