I'm writing an application to send faxes trought FAXCOMEXLib. I used this code:
Dim objFaxServer As New FAXCOMEXLib.FaxServer
Dim objFaxDocument As New FAXCOMEXLib.FaxDocument
Dim JobID As Object
Try
objFaxServer.Connect(txtFaxServer.Text)
objFaxDocument.Body = Me.txtFile.Text
objFaxDocument.DocumentName = "My First Fax"
objFaxDocument.Recipients.Add(Me.txtNumber.Text, "")
objFaxDocument.AttachFaxToReceipt = True
objFaxDocument.Note = "Here is the info you requested"
objFaxDocument.Subject = Me.txtFaxID.Text
objFaxDocument.ReceiptAddress = "test#tin.it"
objFaxDocument.CoverPageType = FAXCOMEXLib.FAX_COVERPAGE_TYPE_ENUM.fcptNONE
objFaxDocument.Priority = FAXCOMEXLib.FAX_PRIORITY_TYPE_ENUM.fptNORMAL
objFaxDocument.ReceiptType = FAXCOMEXLib.FAX_RECEIPT_TYPE_ENUM.frtMAIL
objFaxDocument.ScheduleType = FAXCOMEXLib.FAX_SCHEDULE_TYPE_ENUM.fstNOW
JobID = objFaxDocument.ConnectedSubmit(objFaxServer)
objFaxServer.Disconnect()
'MessageBox.Show("The Job ID is :" & JobID(0), "Information")
Catch ex As Exception
MessageBox.Show(ex.ToString, "Error")
End Try
I have two modems (Modem1 or Modem2). When using this code sending a fax is carried out by the first available modem.
But I need to send faxes using Modem1 or Modem2 under my rules. How can I select a specific modem to send a fax?
Related
I'm going mad here!
Sending emails in VB.Net is working fine, even the read/delivery receipts are working. What it's not doing, is putting a copy of the email it sends in the sent folder. Is there something else I need to do as I've searched high a low for a solution but can't see anything.
EMail.From = New MailAddress(sSENDERaddress)
EMail.Body = sMessage
EMail.Subject = sSubject
If sAttached <> "" Then
Dim mAttachment As New Attachment(sAttached)
EMail.Attachments.Add(mAttachment)
End If
EMail.Headers.Add("Return-Receip-To", sSENDERaddress)
EMail.Headers.Add("Disposition-Notification-To", sSENDERaddress)
EMail.Headers.Add("Return-Path", sSENDERaddress)
EMail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure Or DeliveryNotificationOptions.OnSuccess ' this will send an email to the SENDER'S email address confirming that the original email was sent. If the sender doesn't get the email, then it didn't go. Simples
SMTPServer.Host = GetMailServerAddress()
SMTPServer.Port = GetMailPort()
SMTPServer.Credentials = Authentication
Try
SMTPServer.Send(EMail)
'EMail.Dispose()
bRET = True
Catch ex As Exception
''debug.Print(ex.Message)
ExceptIt(ex.Message)
'EMail.Dispose()
bRET = False
End Try
I've found a few more posts on this subject, and it looks like you can't do it. The only Heath Robinson solution is to add a BCC to my sending address...
UPDATE: For those interested, it's not an SMTP function, but an IMAP one. I suppose, if you want to, you can spend hours working the code out for this, but I found this
https://www.example-code.com/vbnet/sendWithCopyToSentMailbox.asp
Where you simply append to the sent items...
' Now use Chilkat IMAP to save the email to Inbox.Sent
Dim imap As New Chilkat.Imap
' Connect to an IMAP server.
' Use TLS
imap.Ssl = True
imap.Port = 993
success = imap.Connect("mail.mydomain.com")
If (success <> True) Then
Console.WriteLine(imap.LastErrorText)
Exit Sub
End If
' Login
success = imap.Login("myLogin","myPassword")
If (success <> True) Then
Console.WriteLine(imap.LastErrorText)
Exit Sub
End If
' The AppendMail method uploads an email to an IMAP server
' and saves it in the mailbox specified:
success = imap.AppendMail("Inbox.Sent",email)
If (success <> True) Then
Console.WriteLine(imap.LastErrorText)
Exit Sub
End If
Console.WriteLine("Mail saved to Inbox.Sent")
I am wondering if how it could be done. Is it possible to do it?
Here is my simple code:
Try
MsgBox("Please wait this may takes time to load", vbInformation, "Mailing System")
System.Diagnostics.Process.Start("mailto:" & txtEmailadd.Text)
Catch ex As Exception
MsgBox(ex.Message & " Having some technical difficulties, kindly check if the email textbox has data in it", vbCritical, "System Advisory")
End Try
I want to add an attachment inside of this before the default client loads. Unfortunately, i don't find any answers in the web. Can you give some advice? Thanks so much in advance.
you need to call the MailMessage.Attachments(). Here's the example code:
Dim MailMsg as New MailMessage
Dim loAttachment As Attachment = Nothing
Dim ls_email_attach as String
Dim server as String
ls_email_attach = "attach.xls"
server = "Mail server info"
//add the attachment
If Not ls_email_attach.Trim = "" Then
loAttachment = New Attachment(ls_email_attach)
loMailMsg.Attachments.Add(loAttachment)
End If
//send the email
MailMsg = New SmtpClient(server)
MailMsg.Send(loMailMsg)
Please see this for reference.
Hope it helps
I currently have a mail system using Microsoft's exchange server (OWA). I am trying to authenticate a user and send an email using pure Visual Basic code.
I have been trying to use a library called Aspose, however; I have no idea if I'm on the right track. I can not get it to work and I am not sure (since this is a company mail server) whether it's the server or it's my code.
Currently I have,
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create instance of ExchangeClient class by giving credentials
Dim client As Aspose.Email.Exchange.ExchangeClient = New Aspose.Email.Exchange.ExchangeClient("https://MAILSERVER.com/username/", "username", "password", "https://MAILSERVER.com/")
' Create instance of type MailMessage
Dim msg As Aspose.Email.Mail.MailMessage = New Aspose.Email.Mail.MailMessage()
msg.From = "username#MAILSERVER.com"
msg.To = "receivingemail#gmail.com"
msg.Subject = "test"
msg.HtmlBody = "test"
' Send the message
Try
client.Send(msg)
Console.WriteLine("made it")
Catch ex As Exception
Console.WriteLine("failed")
End Try
End Sub
I have obviously changed the username, password, and server name fields to generic ones but with (what I think is the right credentials) the output is always failed.
Can anybody help me out please?
Here is what I use:
Public Shared Function SendEMail(MailMessage As System.Net.Mail.MailMessage) As String
ErrorMess = ""
' Default the from address, just in case is was left out.
If MailMessage.From.Address = "" Then
MailMessage.From = New Net.Mail.MailAddress("donotreply#MAILSERVER.com")
End If
' Check for at least one address
If MailMessage.To.Count = 0 AndAlso MailMessage.CC.Count = 0 AndAlso MailMessage.Bcc.Count = 0 Then
ErrorMess = "No Addresses Specified"
Return ErrorMess
End If
' Create a SMTP connedction to the exchange 2010 load balancer.
Dim SMTPClient As New System.Net.Mail.SmtpClient("MAILSERVER.com")
Try
Dim ValidUserCredential As New System.Net.NetworkCredential
ValidUserCredential.Domain = "MAILSERVER.com"
ValidUserCredential.UserName = My.Resources.EmailUserName
ValidUserCredential.Password = My.Resources.EmailPassword
SMTPClient.UseDefaultCredentials = False
SMTPClient.Credentials = ValidUserCredential
SMTPClient.Send(MailMessage)
Return "Mail Sent"
Catch ex As Exception
ErrorMess = ex.Message & " " & ex.InnerException.ToString
Return ErrorMess
End Try
End Function
The ExchangeClient class is used to connect to Exchange server using the WebDav protocol and is used with Exchange Server 2003 and 2007. For OWA, you need to use the IEWSClient interface as shown in the following sample code. It has an Office365 test account that you can use to send a test email (the test account is solely for testing purpose and is not property of Aspose. I just created it for assisting you in testing the functionality). Please try it and if you face any problem, you may share the porblem on Aspose.Email forum for further assistance.
' Create instance of IEWSClient class by giving credentials
Dim client As IEWSClient = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "UserTwo#ASE1984.onmicrosoft.com", "Aspose1234", "")
' Create instance of type MailMessage
Dim msg As New MailMessage()
msg.From = "UserTwo#ASE1984.onmicrosoft.com"
msg.[To] = "receiver#gmail.com"
msg.Subject = "Sending message from exchange server"
msg.IsBodyHtml = True
msg.HtmlBody = "<h3>sending message from exchange server</h3>"
' Send the message
client.Send(msg)
I work with Aspose as Developer evangelist.
I have a kind of simple issue, I have a section of code that sends out a test email and just before this process occurs, I'd like a marquee progress bar to appear, indicating that something is happening.
However, the progress bar does not appear until the test email has been sent.
I've tried experimenting with the Sleep function, but the progress bar still wont appear until after the test email sends.
Does anyone know why?
Code: (Note: GroupBoxTesting contains the Progress bar)
Private Sub BTMsendmailtest_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTMsendmailtest.Click
GroupBoxTesting.Visible = True
Threading.Thread.Sleep(500)
Try
Dim Mail As New MailMessage
Mail.Subject = "Test email for Email Alerts!"
Mail.To.Add(TXTemailaddy.Text)
Mail.From = New MailAddress(TXTsmtpusr.Text)
Mail.Body = "This is a test message from Email Alerts!" & Environment.NewLine & Environment.NewLine & "If you are reading this, then Email Alerts! is properly configured."
Dim SMTP As New SmtpClient(TXTsmtpsvr.Text)
If CHKEnableSSL.Checked = True Then
SMTP.EnableSsl = True
Else
SMTP.EnableSsl = False
End If
SMTP.Credentials = New System.Net.NetworkCredential(TXTsmtpusr.Text, TXTsmtppwd.Text)
SMTP.Port = TXTsmtpport.Text
SMTP.Send(Mail)
SendingPB.Value = False
MessageBox.Show("A test email has been sent to " & TXTemailaddy.Text & " from " & TXTsmtpusr.Text & "." & Environment.NewLine & Environment.NewLine & "If you did not recieve an email, please check your settings and try again.", "Test Email")
GroupBoxTesting.Visible = False
Catch ex1 As Exception
SendingPB.Value = False
GroupBoxTesting.Visible = False
MessageBox.Show(ex1.Message)
Return
End Try
End Sub
You've told the UI thread (which is the thread your code as it is is currently running on) to go to sleep, so it goes to sleep and doesn't do anything for the specified time. Even without the Sleep, it may be that the UI thread is too busy sending the email to update the display of the marquee progress bar.
You could either use a BackgroundWorker to send the email, or use the SmtpClient.SendAsync Method. The latter includes an example; there is another example at How do I send email asynchronously?.
I had the error using Excel Automation with a VB.Net application while processing and writing over 20,000 rows. I used this code to resolve the issue.
' ---- Write the Row to the Worksheet
Threading.Thread.Sleep(1000)
lstrStartingColRow = "A" & mlngIdx.ToString
If .InsertArrayIntoRow(istrWorksheetName:=lstrWorksheetName,
istrStartingCell:=lstrStartingColRow,
istrArrayOfData:=mstrExcelRow) = False Then
Throw New Exception("Insert Error *************************")
End If
I'd like to be able to create, name and store individualized reports (school report cards, actually) with VB.Net and Crystal Reports using data from our SQL database.
It would be even better to be able to automatically generate individualized e-mails using e-mail addresses stored in the database, attaching the aforementioned PDF reports and sending them off.
Has anyone attempted anything like this before?
TIA for any help/pointers!
1. Create PDF programatically
Depending on the version of crystal, the export function will look similar to this
Dim objApp As CRAXDRT.Application
Dim objRpt As CRAXDRT.Report
Dim Path As String = "MyReport.rpt"
objApp = new CRAXDRT.Application
objRpt = objApp.OpenReport(Path)
With objRpt
.ExportOptions.FormatType = crEFTPortableDocFormat
.ExportOptions.DestinationType = crEDTDiskFile
.ExportOptions.DiskFileName = "MyReport.PDF"
.ExportOptions.PDFExportAllPages = True
.Export( False )
End With
2. Send email with a PDF attachment
The "send" part will look like this:
Dim email As New MailMessage()
''//set the reply to address and the to address
email.To.Add(New MailAddress("student#domain.com", "Studen Name"))
email.ReplyTo = New MailAddress("youremail#domain.com", "Your name")
''//Assign the MailMessage's properties
email.Subject = "Your scorecard file"
email.Body = "Attached is the file you asked<br />Regards!"
email.IsBodyHtml = True
''//attach the file
email.Attachments.Add(New Attachment("c:\temp\myreport.pdf"))
Dim smtp As New SmtpClient
Try
smtp.Send(email)
Catch ex As Exception
messageBox("cant send")
End Try