Code to send email with attachment

Ashfaque

Search Beautiful Girls from your town for night
Local time
Today, 15:27
Joined
Sep 6, 2004
Messages
897
Hi, :)

I have a module that sends data from db tables to Excel sheet in a desired colored format (upon clicking cmd btn). Excel Sheet is placed in the same folder where it should be.

I need to send that created sheet to few members using thier emaill ids along with this sheet as attachment.

I will place some text boxes on a form like To, Subject, MsgTextBox and then click the send button to execute the code I am looking for

Do somebody have such kind code to perform this task?

With kind regards,

Ashfaque
 
Thanks.

But your code says "User-defined type not defined" at below line while compile.. Where to define?

Dim iMsg As New CDO.Message

Regards
 
Do you any one have live example? Please load the code here...
 
You need to set a reference to CDO. Read more of that thread. The information is there.
 
Lagbolt,

I used your code and make reference of CDO. After compilation no error found.

Can you let me know how to use it to send the email ?
 
Hey, how are you? This is a pretty old thread!.
You'd call this routine just like any other subroutine. If the signature of the sub is...
Code:
Public Sub Send(recipients As String, from As String, subject As String, _
  smtpServer As String, Optional msg As String, Optional attachPath As String)
...you can call it from a command button (cmdSend) using code like...
Code:
Private Sub cmdSend_Click()
  Send _
    "you@yourisp.com;me@myisp.ca", _
    "from@somedomain.com", _
    "This is the Subject Line", _
    "mail.somedomain.com", _
    "To Whom It May Concern:" & vbcrlf & _
    "  This is the body text of the email." & vbcrlf & _
    "Sincerely, " & vbcrlf & _
    "lag", _
    "C:\FilePathToAttachmentFile.xls"
End Sub
In practice I'd probably store and retrieve the SMTP Server name from system settings rather than pass it in hardcoded as a parameter on every call. A valid mail server name will be the same as what you'd specify setting up a regular email account.
Post back if you need more info.
 
Thanks.

I will try to use it...

Regards,
 
Lagbolt,

Can you please let me know from where I can get below answers from your code?

1. "you@yourisp.com;me@myisp.ca", _
"from@somedomain.com", _

2. "mail.somedomain.com", _

I mean are they somewhere in my outlook express? I dont know much of outlook..pls extend help.

Ashfaque
 
Hi,

I tried and it produced error. I have attached code error herewith.

Please extend your help.

With kind regards,
Ashfaque
 

Attachments

  • Send Mail Code Error.JPG
    Send Mail Code Error.JPG
    76.8 KB · Views: 151
Go to the screen where you configure your email address in Outlook Express. Find the Outgoing Mail Server Name or the SMTP Server. Look for a field that is labelled with one or more of these words: Outgoing, SMTP, Mail, Server. The data in this field will commonly take a format like 'mail.domain.com' where domain is the word after the '@' in your email address, for example, if your email address is 'ashfaque@comcast.net,' then it is likely that your outgoing mail server is named 'mail.comcast.net'.
If your Outlook Express account can send mail, then the server name is there for you to find. Find it, and pass it to the routine as string in the 'smtpServer' field.
 

Users who are viewing this thread

Back
Top Bottom